need help error checking my string input.

i need to error check this code
SkaDan = 'what are you looking for today? skating or dance\n';
Ans = input(SkaDan,'s');
i need it to move on if it spelled correct but if its not then i need it to spit out the message "ERROR, what are you looking for today? skating or dance"

 Respuesta aceptada

Image Analyst
Image Analyst el 3 de Mayo de 2022
Here's one way:
replyOK = false;
SkaDan = 'What are you looking for today? Skating or dance?\n';
while ~replyOK
reply = input(SkaDan, 's');
if strcmpi(reply, 'skating') || strcmpi(reply, 'dance')
replyOK = true; % or "break" to break out of loop
end
end

Más respuestas (0)

Categorías

Más información sobre Just for fun en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Etiquetas

Preguntada:

el 3 de Mayo de 2022

Comentada:

el 3 de Mayo de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by