How can i stop the loop iteration using pushbutton callback in MATLAB GUI?

조회 수: 1 (최근 30일)
I have GUI which has pushbutton to stop the for loop iteration. the code structure for stop button callback is follows
g = 1
handles.g = g
guidata(hObject,handles)
When i press the button, it sets the value of g = 1;
In the iteration loop, i have passed the updated value of g using
g = handles.g
and issuing a condition to stop the loop iterations
if g == 1
return
end
however, the iteration loop does not stop, since the value of g resets to 0
why does this happen ?

채택된 답변

Image Analyst
Image Analyst 2018년 11월 28일
I have a very small demo that does exactly that. It start counting, then when you press stop, it stops counting and updating the text label on the GUI. Then when you press Go, it starts counting and updating the label again.
  댓글 수: 1
Roche de Guzman
Roche de Guzman 2021년 1월 20일
I tried doing a similar process in MATLAB app but the changing of user data to true (1) only happens after the iteration (on queue). I have attached the mlapp file.

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

추가 답변 (1개)

YT
YT 2018년 11월 28일
If you want to stop your iteration (for/while loop), you could try break instead of return.
  댓글 수: 1
VBBV
VBBV 2018년 11월 28일
편집: VBBV 2018년 11월 28일
yes, i have tried that as well. still it does not stop. because it does not enter the if loop, since the value of g resets to 0. why does this happen ?

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

카테고리

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