Stop a while loop using a GUI
4 次查看(过去 30 天)
显示 更早的评论
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.
0 个评论
采纳的回答
Jan
2013-1-24
编辑:Jan
2013-1-24
A short example:
h = uicontrol('Style', 'PuchButton', 'String', 'Stop', ...
'Callback', 'delete(gcbo)');
while ishandle(h)
disp(datestr(now, 0));
pause(0.25);
end
2 个评论
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
2013-1-24
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
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!