So I have a UI panel set up in my GUI to take in a subplot(s) I've created. Essentially different number of plots should be able to be displayed but sometimes the remains of the plots still exist. Right now I have a clear button setup to hide the axes' visibility in the UI panel and then delete the children of the plots (ie the remaining lines).
All of this works except for the fact I cannot get rid of the legend boxes displayed. I can clear the data within the legend boxes but cannot clear them themselves.
I built the legends to even initilize in the handles structure so I can use the 'boxoff' line of code but it doesn't work.
% hides all axes in settings
try set(findobj(gcf, 'type','axes'), 'Visible','off');catch error = errordlg('Plot(s) have already been cleared','File Error');end% Deletes remainders of hidden axes including lines
try children = get(handles.plot1, 'children'); delete(children(1)); delete(children(2));endtry children = get(handles.plot2, 'children'); delete(children(1)); delete(children(2));endtry children = get(handles.plot3, 'children'); delete(children(1));endtry children = get(handles.plot4, 'children'); delete(children(1));end%Attempt to hide remaining legends from *** plotting
try legend(handles.errorLegend,'boxoff'); %hide the legend created under handle 'errorLegend'
legend(handles.visLegend,'boxoff'); legend(handles.weatherLegend,'boxoff');end
What would be the best way to clear the axes within this uipanel or simply clear the index box?
Best Answer