how to interrupt a while loop??

14 Ansichten (letzte 30 Tage)
IPSAS
IPSAS am 6 Jun. 2012
Kommentiert: Danilo Teran am 10 Mai 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????

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 6 Jun. 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 Kommentare
Image Analyst
Image Analyst am 13 Apr. 2013
Walter might want to add this to the FAQ. It's useful and asked fairly often, but I don't think it's on there yet. By the way, you can also do it with a checkbox. Button A makes the "Finish Now" checkbox become visible and clears it. When the user checks the box, the loop will "break" because it gets the checkbox value and checks to see if it's checked.
Danilo Teran
Danilo Teran am 10 Mai 2017
Hi I did your suggestion, but I can never stop routine on Pushbutton A. Shall I do something extra in PushburronB

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Geoff
Geoff am 6 Jun. 2012
In your GUI, set some user data to your GUI handle.
In your loop, check this data and break accordingly.

Kategorien

Mehr zu MATLAB Compiler finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by