How to control the pushbutton in a while loop in Matlab GUI

조회 수: 20 (최근 30일)
Alan
Alan 2021년 8월 17일
편집: Walter Roberson 2021년 8월 18일
Hi all,
I am now writting a pushbutton callback function by using a while loop like below
while i > 0 ;
var = get(handles. pushbutton, ' value');
if var ==1
plot(x,y);
else
error('range quitting')
end;
end
However, by this way, the pushbutton will automatically be clicked and the while loop will run continously.
I would like to run the loop each time only when I click the pushbutton.
Can anyone help me to solve the problem?
Many thanks.

채택된 답변

Adam Danz
Adam Danz 2021년 8월 17일
> I would like to run the loop each time only when I click the pushbutton.
I don't know whether you're using app designer, GUIDE, or a custom GUI/App which prevents me from getting too specific. I'm not sure what this means: " the pushbutton will automatically be clicked". Also, where is this while-loop and what is i? It's not clear why a while-loop is needed.
Here the general steps you can take.
  1. If the button should produce a figure, assign a callback function to the button and move the plotting code to the callback function. The code will be evoked when the user pressed the button.
  2. If the button should start/stop a longer plotting process such as an animation or updating a plot according to incoming data, you could use a state button (on/off states) that determines when the plotting should happen or pause. Keep in mind that when a callback function completes, its variables are cleared so you'll have to store the progress somewhere so the plotting function can pick up where it left off next time it's evoked.
  댓글 수: 7
Adam Danz
Adam Danz 2021년 8월 18일
I have no idea how the lines are created but their handles need to be stored somehwere within the app. Since I don't know whether you're using app designer or something else, I can't suggest a specific method (use a private property for app designer, use guidata with GUIDE, use setappdata otherwise).
If the button merely deletes 1 line every time it's pressed, you'll just access the list of handles and delete the first or last handle depending on whether you want to delete the most recent or earliest lines.
I really can't give any more specific advice without knowing a lot more about what the actual goal is.
Alan
Alan 2021년 8월 18일
Thanks for your suggestions and help. Some of your advices are useful to solve the probelm. Thanks a lot.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Graphics Performance에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by