How do you clear multiple elements of an axes in a GUI
18 views (last 30 days)
Show older comments
Hiranth Shenal Fernando
on 18 Jan 2019
Answered: Hiranth Shenal Fernando
on 18 Jan 2019
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));
end
try
children = get(handles.plot2, 'children');
delete(children(1));
delete(children(2));
end
try
children = get(handles.plot3, 'children');
delete(children(1));
end
try
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?
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Legend in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!