If and elseif problem

10 visualizaciones (últimos 30 días)
vlad vladut
vlad vladut el 15 de Nov. de 2015
Comentada: Star Strider el 15 de Nov. de 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

Respuesta aceptada

Star Strider
Star Strider el 15 de Nov. de 2015
Editada: Star Strider el 15 de Nov. de 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 comentarios
vlad vladut
vlad vladut el 15 de Nov. de 2015
Ty a lot works nicely...saved me:))
Star Strider
Star Strider el 15 de Nov. de 2015
My pleasure.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by