is it possible for if/ else if statements to accept multiple string inputs?
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
if solid == string('yes , YES')
disp('True')
elseif solid == string('no , NO')
disp('False')
end
I'm honestly kinda lost. I know that the if and elseif staments are working with simple yes and no sting inputs but when i try and use multiple strings it throws an error. if someone can point me in the right direction it would be greatly appriciated.
0 commentaires
Réponses (1)
Walter Roberson
le 6 Oct 2022
if ismember(solid, {'yes', 'YES'})
but consider instead
if strcmpi(solid, 'yes')
the i in strcmpi means case-insensitive -- similar to as-if you had compared
if strcmp(lower(solid), lower('yes'))
(except possibly with different behaviour on some edge cases involving unusual characters such as ß whose lower-case form is different than you might expect.)
0 commentaires
Voir également
Catégories
En savoir plus sur Data Type Conversion dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!