フィルターのクリア

Can anyone tell me where i went wrong in my If elseif else

1 回表示 (過去 30 日間)
Tony Hill
Tony Hill 2014 年 4 月 27 日
編集済み: Andrew Newell 2014 年 4 月 28 日
Ok im doing this problem: Write a function (named as Exam2_part3.m) to accept a numeric vector and an integer choice as input arguments, in this order. The choice can only be 1 or 2, otherwise display an explanation. If the value of the choice is 1, the function will do “plot(x)”. If the value of the choice is 2, the function will do “disp(x)”. Do this using eval. I wrote out the eval statement and im trying to answer using a if elseif else statement. what am i doing wrong heres my code:
function x = Exam2_part3
x = [1,2];
myCommand = 'plot(x)';
eval(myCommand)
if x = 1;
'plot(x)';
elseif x> 1 < 2
then eval(myCommand)
else x>2;
disp('The choice can only be 1 or 2')
end
if someone could tell me where my error lies that would be very helpful

採用された回答

Roberto
Roberto 2014 年 4 月 28 日
Please read the relational operators and the if/elseif/else documentation, the problem is your syntax, here's how to properly write the commands, but your code won't work anyway!! I highly recommend you start with the getting started section of matlab. Try THIS
if x == 1
x = 'plot(x)';
elseif (x > 1) && (x < 2 )
eval(myCommand)
elseif x>2
disp('The choice can only be 1 or 2')
end

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeData Import and Export についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by