Hey everyone,
I need to stop a while loop using a 'Stop' button in a GUI and i was wondering what are the best ways of doing that.

 採用された回答

Jan
Jan 2013 年 1 月 24 日
編集済み: Jan 2013 年 1 月 24 日

2 投票

A short example:
h = uicontrol('Style', 'PuchButton', 'String', 'Stop', ...
'Callback', 'delete(gcbo)');
while ishandle(h)
disp(datestr(now, 0));
pause(0.25);
end
Check out the famous 41 GUI example.

2 件のコメント

Raldi
Raldi 2013 年 1 月 24 日
Ill go with this answer as i already have created a pushbutton. Will there be a problem if the pushbutton is created in another function and i just use findobj or something similar?
Jan
Jan 2013 年 1 月 24 日
On one hand: no, you can create the button anywhere and use any method to obtain the handle. On the other hand: simply try it - when you do not have problems, it works.

サインインしてコメントする。

その他の回答 (2 件)

Sean de Wolski
Sean de Wolski 2013 年 1 月 24 日

0 投票

Have the while-loop check if a togglebutton uicontrol has been pushed (i.e. what is it's value). If it has the loop will end
while(get(handles.togglebutton,'value')); %handles.togglebutton is handle to button
do_stuff;
drawnow; %force event queue update
end

カテゴリ

ヘルプ センター および File ExchangeInteractive Control and Callbacks についてさらに検索

製品

質問済み:

2013 年 1 月 24 日

回答済み:

2014 年 9 月 21 日

Community Treasure Hunt

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

Start Hunting!

Translated by