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 Center および File ExchangeDownloads についてさらに検索

製品


リリース

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by