If you already have the axes handle (from either figure.Children
or otherwise), you can simply use delete
to remove it from the figure regardless of it's visibility.
fig = figure();
hax = axes('Parent', fig);
% Delete the axes directly
delete(hax)
If you don't have access to the handle, you can get it using findobj
or findall
(findall
even locates axes
with HandleVisibility
turned to 'off'
) to locate axes which belong to your figure and then delete
to remove it.
delete(findobj(gcf, 'type', 'axes'));
% delete(findall(gcf, 'type', 'axes'));
If your axes has a specific Tag
property, you can further filter by that
delete(findobj(gcf, 'type', 'axes', 'tag', 'mytag'));
% delete(findall(gcf, 'type', 'axes', 'tag', 'mytag'));
You can pass any property / value pair to findobj
and findall
so you could even just delete all invisible axes:
delete(findobj(gcf, 'type', 'axes', 'visible', 'off'))