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!