clear axes in GUI figure in callback function

조회 수: 8 (최근 30일)
Marc Jakobi
Marc Jakobi 2013년 9월 3일
댓글: Noah Griffiths 2020년 12월 22일
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

채택된 답변

Image Analyst
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
Marc Jakobi
Marc Jakobi 2013년 9월 5일
편집: Marc Jakobi 2013년 9월 5일
Thanks. When I type "help cla" into the Matlab command window, it tells me to use upper case letters for RESET. Lower case did not work either. I found out what my problem was though.
cla(handles.Scosts)
did the job, as you mentioned in your first answer.
Noah Griffiths
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개)

Marc Jakobi
Marc Jakobi 2013년 9월 4일
Thanks for the reply. It didn't work though. I tried putting
cla(handles.Scosts,'RESET')
at the beginning of the callback function, but I get the following error message:
Error using clo (line 32)
Unknown command option.
Error in cla (line 29)
clo(ax, extra{:});
Error in OnlineTool>PVInvCost_Callback (line 91)
cla(handles.Scosts,'RESET')
Error in gui_mainfcn (line 96)
feval(varargin{:});
Error in OnlineTool (line 42)
gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)OnlineTool('PVInvCost_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
  댓글 수: 1
Marc Jakobi
Marc Jakobi 2013년 9월 4일
sorry, I didn't mean to post this as an answer.

댓글을 달려면 로그인하십시오.


Marc Jakobi
Marc Jakobi 2013년 9월 5일
I figured out the solution to my second problem. Just had to set the callback function of all the other sliders to the one of the first slider in the property inspector.

카테고리

Help CenterFile Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by