MATLAB: Elseif and if commands

elseif

Hi guys. please can someone help me locate and fix this error that i keep getting in my file.. i am trying to basically say that at the start the user defines if a plate is fixed or simply supported (simple). from here if it is defined as simple then all edges become 19 and corner becomes 18 and if user defines it to be fixed then all edges become 21 and corners become 22.For some reason it keeps giving an error. 🙁 i have shown below the term Endcond which just stands for end condition of plate (simple of fixed)
Endcond= 'input'
Endcond=input('Enter simple or fixed')
if Endcond==('simple')
corner=18;
edge=19;
elseif Endcond==fixed
corner=22;
edge=21;
end
below is the error i keep getting…
Enter the apllied load (kN/m)20
Endcond =
input
Enter simple or fixedsimple Error using input Undefined function or variable 'simple'.
Error in corrected (line 14) Endcond=input('Enter simple or fixed')
Enter simple or fixed

Best Answer

You need to call input with the 's' option to get it to return a string (without this option is slow and a security risk anyway), and also use strcmp or strcmpi to check the strings:
str = input('Enter "simple" or "fixed": ','s');
if strcmpi(str,'simple')
corner = 18;
edge = 19;
elseif strcmpi(str,'fixed')
corner = 22;
edge = 21;
else
% what to do?

end
Alternatively you could use switch:
str = input('Enter "simple" or "fixed": ','s');
switch lower(str)
case 'simple'
corner = 18;
edge = 19;
case 'fixed'
corner = 22;
edge = 21;
otherwise
% what to do?
end