If and elseif problem

12 ビュー (過去 30 日間)
vlad vladut
vlad vladut 2015 年 11 月 15 日
コメント済み: Star Strider 2015 年 11 月 15 日
I have matlab2007 and if i use multiple elseif the program don't run the second or third eleseif. This is the code... x=input('Give x a value x:') if x<-2 f=1 elseif -2<x<3 f=x+1 elseif x>=3 f=x^2 end

採用された回答

Star Strider
Star Strider 2015 年 11 月 15 日
編集済み: Star Strider 2015 年 11 月 15 日
The condition in the first elseif statement is not stated correctly. This should work:
xc=inputdlg('Give x a value x:');
x = str2num(xc{:});
if x<-2
f=1
elseif (-2<x) && (x<3)
f=x+1
elseif x>=3
f=x^2
end
  3 件のコメント
vlad vladut
vlad vladut 2015 年 11 月 15 日
Ty a lot works nicely...saved me:))
Star Strider
Star Strider 2015 年 11 月 15 日
My pleasure.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGet Started with MATLAB についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by