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

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.

Answers (1)

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.)

Categories

Products

Release

R2022a

Asked:

on 6 Oct 2022

Answered:

on 6 Oct 2022

Community Treasure Hunt

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

Start Hunting!