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????

 채택된 답변

Walter Roberson
Walter Roberson 2012년 6월 6일

3 개 추천

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

IPSAS
IPSAS 2012년 6월 6일
it can work whith the programmatically GUI?
Steven
Steven 2013년 4월 13일
Thank you so much Walter! I've been looking for a way to stop the loop for the whole day.
Image Analyst
Image Analyst 2013년 4월 13일
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 2017년 5월 10일
Hi I did your suggestion, but I can never stop routine on Pushbutton A. Shall I do something extra in PushburronB

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

추가 답변 (1개)

Geoff
Geoff 2012년 6월 6일

0 개 추천

In your GUI, set some user data to your GUI handle.
In your loop, check this data and break accordingly.

카테고리

도움말 센터File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기

태그

질문:

2012년 6월 6일

댓글:

2017년 5월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by