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

1 visualización (últimos 30 días)
Batuhan Yildiz
Batuhan Yildiz el 23 de Oct. de 2022
Comentada: Image Analyst el 23 de Oct. de 2022
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.

Respuestas (2)

Walter Roberson
Walter Roberson el 23 de Oct. de 2022
See "switch" and "case"

Image Analyst
Image Analyst el 23 de Oct. de 2022
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 comentarios
Batuhan Yildiz
Batuhan Yildiz el 23 de Oct. de 2022
Thx but I got a question what was the following code?
if isempty(answer)
return;
uiwait(helpdlg(message))
Image Analyst
Image Analyst el 23 de Oct. de 2022
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.

Iniciar sesión para comentar.

Categorías

Más información sobre Downloads en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by