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

 採用された回答

Stephen23
Stephen23 2017 年 1 月 24 日
編集済み: Stephen23 2017 年 1 月 24 日

0 投票

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 件のコメント

ehsan Zahoor
ehsan Zahoor 2017 年 1 月 24 日
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 2017 年 1 月 24 日
OMG YOU ARE THE BEST! thank you so so much

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by