MATLAB Answers

0

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

Asked by Vasishta Bhargava on 27 Nov 2018
Latest activity Answered by Image Analyst
on 28 Nov 2018
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 ?

  0 Comments

Sign in to comment.

2 Answers

Answer by Image Analyst
on 28 Nov 2018
 Accepted Answer

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.

  0 Comments

Sign in to comment.


Answer by YT
on 28 Nov 2018

If you want to stop your iteration (for/while loop), you could try break instead of return.

  1 Comment

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 ?

Sign in to comment.