If and elseif problem

조회 수: 13 (최근 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 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