clear axes in GUI figure in callback function
3 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Image Analyst
2013 年 9 月 3 日
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 件のコメント
Noah Griffiths
2020 年 12 月 22 日
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)
その他の回答 (2 件)
参考
カテゴリ
Help Center および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!