If and elseif problem

11 次查看(过去 30 天)
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:))

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by