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.
0 个评论
回答(2 个)
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 个评论
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 Exchange 中查找有关 Whos 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!