MATLAB: How can i correctly write an if “yes or no” statement

ifif conditionalMATLABstatement

For Example, x=input('Do you know the area of your building?(yes/no)' ,'s') if (x=='yes') area=input('What is the area of your building?') elseif (x=='no') shape=input('is your building circular or rectangular?') end How could i make it so that if the input is "yes" or "no" that it would do one of the following commands?

Best Answer

if strcmpi(x, 'yes')
...
elseif strcmpi(x, 'no')
...
else
error('Please type "yes" or "no"');
end
The == is the elementwise comparison, which fails when x and 'yes' have a different number of characters.