clear axes in GUI figure in callback function
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Marc Jakobi
el 3 de Sept. de 2013
Comentada: Noah Griffiths
el 22 de Dic. de 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 comentarios
Respuesta aceptada
Image Analyst
el 3 de Sept. de 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 comentarios
Noah Griffiths
el 22 de Dic. de 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)
Más respuestas (2)
Ver también
Categorías
Más información sobre Interactive Control and Callbacks en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!