Break loop with a click of a button?

I am using GUIDE to make a GUI. I have two buttons. The first one has a while loop ongoing with pause(). The second button I would like to make it so that the first button's loop is stopped immediately. What are some best ways I can achieve this?

Antworten (1)

KSSV
KSSV am 12 Aug. 2016

0 Stimmen

You can put a button and call 'break'....loop will exit once it finds break..
Eg:
for i = 1:100
disp(i)
if i == 77
disp('Got break, I am exiting')
break
end
end

2 Kommentare

JohnJ
JohnJ am 12 Aug. 2016
That is possible but I want my second button to be the one to determine when the loop stop. Say my loop has a pause for 30 seconds per step and clicking the second button will break the loop there and then.
KSSV
KSSV am 16 Aug. 2016
Yes...it is possible...make a function, type break in it and call this function by clicking second button.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Hilfe-Center und File Exchange

Gefragt:

am 12 Aug. 2016

Kommentiert:

am 16 Aug. 2016

Community Treasure Hunt

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

Start Hunting!

Translated by