clear axes in GUI figure in callback function
8 views (last 30 days)
Show older comments
Marc Jakobi
on 3 Sep 2013
Commented: Noah Griffiths
on 22 Dec 2020
Hi.
I designed a GUI figure that makes a contour with a text that changes depending on the values determined by sliders.
Here are my questions (sorted by importance):
1. When I run the figure, everything works fine. But if I change the value of a slider, the text displayed from the previous contour remains in the axes, together with the new one. So after changing the slider values a few times, it fills up with text. Here's an excerpt from the code (simplified a little):
contour(handles.Scosts,x1,x1,p,'LevelStep',2,'Fill','on')
hold on
contour(handles.Scosts,x1,x1,p, [34 34], 'Color','k')
...
text(p_b_opt,c_b_opt,pt,'\leftarrow optimal cost');
Is there a way I can get the callback function to clear the axes from the previous contour every time I run it?
2. In the figure, I use many sliders which each execute the same function which accesses all of their values. The code is pretty long. Is there a way I can get the function to run every time I click one of the sliders without having to copy/paste the entire code to each slider's callback function (in case I want to modify it later)? I have tried putting it into a regular function that executes within the callback functions, but that didn't work, because I have to set many slider values [e.g. set(handles.sliderIntRate,'Value',x)], which the function cannot do, because it doesn't recognize the handles.
Thanks in advance for your help!
Marc
0 Comments
Accepted Answer
Image Analyst
on 3 Sep 2013
Try
cla reset;
Make sure you're current axes is the one you want to clear, otherwise pass in the handle of the axes you want to clear to cla() or axes().
3 Comments
Noah Griffiths
on 22 Dec 2020
Alternatively, in the MATLAB GUI, i could only get cla(app.UIAxes, 'reset') to work
So if this doesn't work, which for me, it didn't then use this. (maybe its deprecated, not sure)
More Answers (2)
See Also
Categories
Find more on Specifying Target for Graphics Output 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!