I want to delete a plot and its colorbar ( actually I want to delete everything in a plot, but that seams to be almost impossible, see make axes invisible or delete plot completely)
I do this:
In the plot
hplot = pcolor(xAxis, yAxis, Data2D);
hcb = colorbar;
handles.image.hColorbar = hcb;
handles.image.hplot = hplot;
guidata(handles.output,handles);
later in the gui:
if (isfield(handles,'image') && isfield(handles.image,'hplot'))
if (handles.image.hplot~=0)
delete(handles.image.hplot);
delete(handles.image.hColorbar);
handles.image.hplot = 0;
end
end
It works for delete(handles.image.hplot)
but fails for handles.image.hColorbar
with invalid handle - why?