how to interrupt a while loop??
16 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
IPSAS
il 6 Giu 2012
Commentato: Danilo Teran
il 10 Mag 2017
in GUI, I try to interrupt a while loop...let's say.. a program initiate while loop when button A are pushed, and i want to stop/interupt the loop by pushing button B.. any idea????
0 Commenti
Risposta accettata
Walter Roberson
il 6 Giu 2012
You cannot do that.
The closest you can get is to have button B set a variable in a place that the code in button A can reach, with that code checking the value periodically. For example,
Button B:
set(handles.buttonA, 'UserData', 'stop');
Button A:
set(handles.buttonA, 'Userdata', []);
while ....
curval = get(handles.buttonA, 'UserData');
if ~isempty(curval) && strcmp(curval, 'stop')
break;
end
....
end
4 Commenti
Danilo Teran
il 10 Mag 2017
Hi I did your suggestion, but I can never stop routine on Pushbutton A. Shall I do something extra in PushburronB
Più risposte (1)
Geoff
il 6 Giu 2012
In your GUI, set some user data to your GUI handle.
In your loop, check this data and break accordingly.
0 Commenti
Vedere anche
Categorie
Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!