How can add stop button and command in GUI
조회 수: 26 (최근 30일)
이전 댓글 표시
Hello MATLAB family,
I am new user of GUI, so not familier with GUI. I have question regarding Stop button. I made one GUI which has Start Measurement and Stop Measurement buttons. From start button I can succesfully start my program, but I don't have any idea how can stop the running program.
Idea behind code is when I press the start button program takes picture one-by-one upto 200 pic. but I want one stop button when I press that button, My program will be stop.
댓글 수: 0
채택된 답변
Rik
2021년 7월 15일
편집: Rik
2021년 7월 15일
The general solution is to have the stop button set a flag (either in the guidata or in the UserData property of an object).
%in your looping code
set(handles.StopButton,'UserData',false)
for picture=1:2000
drawnow
if get(handles.StopButton,'UserData')
break
end
end
%in your button callback:
function StopButtonCallback(obj,event)
set(obj,'UserData',true)
end
댓글 수: 5
Rik
2021년 7월 15일
I prefer keeping the discussion public, so others can learn from this as well. If I send you an email, I can help only 1 person, while if the discussion happens here, I can potententially help many more.
Have you made the edit to my answer (replacing 'false' in the callback with 'true')? If you did, did you try my other suggestions to try to determine why the callback is ignored, even with the call to drawnow?
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Interactive Control and Callbacks에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!