is it possible for if/ else if statements to accept multiple string inputs?

2 views (last 30 days)
if solid == string('yes , YES')
elseif solid == string('no , NO')
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.

Answers (1)

Walter Roberson
Walter Roberson on 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.)




Community Treasure Hunt

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

Start Hunting!

Translated by