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

Stephen23
Stephen23 2018년 6월 12일
편집: Stephen23 2018년 6월 12일
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?
Thank you very much for your response. Yes, I figured it out. I managed to do it using isgraphics command.

댓글을 달려면 로그인하십시오.

답변 (1개)

Image Analyst
Image Analyst 2018년 6월 12일

1 개 추천

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

Thank you very much for your response. This message appears in each iteration in a loop. So while using questdlg I need to press 'continue' or 'quit' or something during each iteration. So it was not ideal for my project. But other than that it works fine. Thank you for your time.
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에 대해 자세히 알아보기

태그

질문:

2018년 6월 12일

댓글:

2018년 6월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by