Having Trouble with My Input Argument!
古いコメントを表示
function output=myfun(x)
x=3
if x<-2
output=-x^2;
elseif (-2<=x)&&(x<0)
output=-2*x;
elseif (0<=x)&& (x<=2)
output=2*x;
elseif x>2
output=x^2;
end
8 件のコメント
Sara
2014 年 7 月 2 日
how do you call this function?
David
2014 年 7 月 2 日
Image Analyst
2014 年 7 月 2 日
編集済み: Image Analyst
2014 年 7 月 2 日
That did not answer here question. Again, how do you call it and what do you pass in for x? For example
>> myfun(50)
Plus, you need to split up -2<=x<0 into two tests, like you did with the elseif right after that one.
David
2014 年 7 月 2 日
James Tursa
2014 年 7 月 2 日
But clearly you must pass something in to use the function as you have it written, even if your "problem statement" doesn't explicitly state so.
David
2014 年 7 月 2 日
Image Analyst
2014 年 7 月 2 日
Even though it doesn't explicitly tell you to pass in anything, it's pretty much implicit that if you want to test your function to see if it works, you must pass in something, like Azzi's showing you, unless you just want to turn in your assignment untested (not a wise idea).
David
2014 年 7 月 2 日
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!