If and elseif problem
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
vlad vladut
am 15 Nov. 2015
Kommentiert: Star Strider
am 15 Nov. 2015
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
0 Kommentare
Akzeptierte Antwort
Star Strider
am 15 Nov. 2015
Bearbeitet: Star Strider
am 15 Nov. 2015
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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!