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

1 次查看(过去 30 天)
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 中查找有关 Whos 的更多信息

产品


版本

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by