need help error checking my string input.

5 vues (au cours des 30 derniers jours)
Riley Phillips
Riley Phillips le 3 Mai 2022
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"

Réponse acceptée

Image Analyst
Image Analyst le 3 Mai 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
  1 commentaire
Riley Phillips
Riley Phillips le 3 Mai 2022
it works!! thank you so much!!!

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Just for fun dans Help Center et File Exchange

Produits


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by