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

 Réponse acceptée

Star Strider
Star Strider le 15 Nov 2015
Modifié(e) : Star Strider le 15 Nov 2015

0 votes

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 commentaires

Jan
Jan le 15 Nov 2015
@vlad vladut: Note that f is undefined for x==-2.
vlad vladut
vlad vladut le 15 Nov 2015
Ty a lot works nicely...saved me:))
Star Strider
Star Strider le 15 Nov 2015
My pleasure.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Centre d'aide et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by