For the command window I am trying to have it respond to my choices

조회 수: 1 (최근 30일)
Batuhan Yildiz
Batuhan Yildiz 2022년 10월 23일
댓글: Image Analyst 2022년 10월 23일
answer = questdlg('Lets order some classic American food', ...
'Wednesday 8:30 ', ...
"Clam chowder","fried catfish","chicken fried steak","chicken fried steak");
if answer
elseif "Clam chowder"
disp([answer ' Smooth taste.'])
elseif "fried catfish"
disp([answer ' very yummy.'])
else "chicken fried steak";
disp([answer 'thats a battered heart attack.'])
end
%I am trying to have the command window say ' Smooth taste.' when I chose Clam chowder. The same goes for the other two choices but I haven't been able to do it.

답변 (2개)

Walter Roberson
Walter Roberson 2022년 10월 23일
See "switch" and "case"

Image Analyst
Image Analyst 2022년 10월 23일
Try this:
answer = questdlg('Lets order some classic American food', ...
'Wednesday 8:30 ', ...
"Clam chowder","fried catfish","chicken fried steak","Clam chowder");
if isempty(answer)
return;
end
if contains(answer, 'clam','IgnoreCase',true)
message = sprintf('The local restaurant has very tasty %s with a smooth taste!', answer);
elseif contains(answer, "catfish",'IgnoreCase',true)
message = sprintf('The local restaurant has very yummy %s!', answer);
elseif contains(answer, "chicken",'IgnoreCase',true)
message = sprintf('Do not order it! The %s is a battered heart attack!', answer);
end
uiwait(helpdlg(message))
  댓글 수: 4
Batuhan Yildiz
Batuhan Yildiz 2022년 10월 23일
Thx but I got a question what was the following code?
if isempty(answer)
return;
uiwait(helpdlg(message))
Image Analyst
Image Analyst 2022년 10월 23일
If the person doesn't click a button but just closes the dialog box by clicking the X in the upper right corner, then the answer will be "empty" so you might as well exit since they did not want to choose one of the answers.
helpdlg displays a popup message with the string you pass it and an "info" icon next to it.
uiwait() makes the code wait until you click OK on that popup message instead of continuing on with the rest of the code.

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

카테고리

Help CenterFile Exchange에서 Downloads에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by