Clear Filters
Clear Filters

elseif and if commands

3 views (last 30 days)
ehsan Zahoor
ehsan Zahoor on 24 Jan 2017
Commented: ehsan Zahoor on 24 Jan 2017
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

Accepted Answer

Stephen23
Stephen23 on 24 Jan 2017
Edited: Stephen23 on 24 Jan 2017
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
  2 Comments
ehsan Zahoor
ehsan Zahoor on 24 Jan 2017
Hi Stephen I am going to try this right now sir! thank you so much for replying i really appreciate it
ehsan Zahoor
ehsan Zahoor on 24 Jan 2017
OMG YOU ARE THE BEST! thank you so so much

Sign in to comment.

More Answers (0)

Categories

Find more on Creating and Concatenating Matrices in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!