I have a matlab gui that shall contain 4 plots. The first plot shall be updated if a different file is selected in a list. the other 3 shall only be visible (and be calculat
I use this:
set(allchild(handles.axes1),'visible','off');
set(handles.axes1,'visible','off');
for hiding my axes. I found the solution here: Visible axes off
I now solved it with
function z_removePlots(handles)
if (isfield(handles,'image') && isfield(handles.image,'hplot'))
if ishandle(handles.image.hplot)
delete(handles.image.hplot);
delete(findall(gcf,'tag','Colorbar'));
handles.image.hplot = 0;
set(handles.axesImage, 'Visible', 'off');
end
end
if (isfield(handles,'contour') && isfield(handles.contour,'hplot'))
if ishandle(handles.contour.hplot)
delete(handles.contour.hplot);
handles.contour.hplot = 0;
ClearLinesFromAxes(handles.axesContour)
set(handles.axesContour, 'Visible', 'off');
end
end
guidata(handles.output,handles);
with
function ClearLinesFromAxes(axisObj)
if ishandle(axisObj)
handles2delete = get(axisObj,'Children');
delete(handles2delete);
end
You have use the handles to the subplots and plots:
h(1)=subplot(221);
p(1)=plot(rand(10,1));
h(2)=subplot(222);
p(2)=plot(rand(10,1));
h(3)=subplot(223);
p(3)=plot(rand(10,1));
h(4)=subplot(224);
p(4)=plot(rand(10,1));
set([h(2) p(2)],'visible','off')
hides the 2nd plot. @Jonas answer seems more complete however. It's certainly easier, because you don't have to collect the children yourself manually as I did here.
You want to hide not only the axes, but all of their children:
handles2hide = [handles.axesImage;cell2mat(get(handles.axesImage,'Children'))];
set(handles2hide,'visible','off')
The cell2mat is needed only if there are more than one handle stored in handles.axesImage
Note that you'll need the full list of handles to make everything visible again.
EDIT
If you want to delete all axes (includes colorbars) and their children on a figure, you can do the following (if you have to exclude certain axes, you can use setdiff
on the lists of handles):
ah = findall(yourFigureHandle,'type','axes')
if ~isempty(ah)
delete(ah)
end