MATLAB: Frustrating for what should be simple… What have I done wrong

elseelseifif statementMATLABmatrix dimensions do not agreewhile

Here is an example of some simple code I have written. When I ask the user for a yes/no answer it works for yes but gives an error when they enter no (matrix dimensions do not agree). However it does work if the input is only a y or n. Why is this?
a = 'no';
while a ~= 'yes'
a = input('Do you like the colour red? (yes/no) ——> ','s');
if a == 'yes'
disp('Good its the best colour ever')
elseif a == 'no'
disp('Whats wrong with you?... TRY AGAIN')
else
disp('Thats not an answer, enter y for yes or n for no.')
end
end
THANKS!!

Best Answer

For strings you shouldn't use == to compare but strcmp for case sensitive comparison or strcmpi for not case sensitive. So this code should work for you:
a = 'no';
while ~strcmpi(a,'yes')
a = input('Do you like the colour red? (yes/no) ——> ','s');
if strcmpi(a,'yes')
disp('Good its the best colour ever')
elseif strcmpi(a,'no')
disp('Whats wrong with you?... TRY AGAIN')
else
disp('Thats not an answer, enter y for yes or n for no.')
end
end