How to check if OK is pressed or not in a msgbox
이전 댓글 표시
Hi,
I would like to know how I can check if OK is pressed or not in a msgbox
I tried using strcmp but there seems to be a problem.
Button = msgbox(sprintf('The TryNumber is %d.\nClick OK to Stop',TryNumber));
if strcmp(Button , 'OK')
#do_something
else
#do_something
end
Can somebody help me resolve this issue. Thank you.
댓글 수: 2
The msgbox help shows that the output is a figure object. Why are you using strcmp on a graphics object?
Note that a msgbox only has one button "OK": what do you want the user to do that would run your alternative code?
Melwin Thomas
2018년 6월 12일
답변 (1개)
Image Analyst
2018년 6월 12일
Try using questdlg() instead:
promptMessage = sprintf('Do you want to Continue processing,\nor Quit processing?');
titleBarCaption = 'Continue?';
buttonText = questdlg(promptMessage, titleBarCaption, 'Continue', 'Quit', 'Continue');
if contains(buttonText, 'Quit')
return;
end
댓글 수: 2
Melwin Thomas
2018년 6월 12일
Image Analyst
2018년 6월 12일
You could add a third option for "non-stop" where if they click that, you set a flag where you basically don't ask them anymore.
카테고리
도움말 센터 및 File Exchange에서 App Building에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!