How do I define a variable I just made with an IF statement?

>> if x1 <= 0
x2 = x1./2
elseif x1 >= 0
x2 >= x1.*2
end
x3 = sqrt(y.^2 + x2.^2);
figure(1)
plot(t,x3)
Undefined function or variable 'x2'

 Réponse acceptée

Thorsten
Thorsten le 26 Oct 2015
Modifié(e) : Thorsten le 26 Oct 2015
It's a typo in the 4th line, remove the > and use
x2 = x1.*2
Note that if x1 is not <= 0, it must be > 0 , so you there is no need to test for >=0 in the elseif clause. So you can simply use else:
if x1 <= 0
x2 = x1./2
else
x2 = x1.*2
end

Plus de réponses (0)

Catégories

En savoir plus sur Data Exploration dans Centre d'aide et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by