use of greater than and less than

3 visualizzazioni (ultimi 30 giorni)
Tim
Tim il 30 Ago 2014
Modificato: per isakson il 30 Ago 2014
Hi,
I am very confused with the matlab format of a range. for example:
for L=10
if 0<L<5,
rad=L+10
else
rad=L+2
end
end
thats my code for saying that if L is less than 5, i want rad to be equal to L+2. however, the display is giving me 20! which is incorrect. What is the convention for defining a range in matlab?

Risposte (1)

per isakson
per isakson il 30 Ago 2014
Modificato: per isakson il 30 Ago 2014
The MATLAB syntax is
if 0<L && L<5,
rad=L+10
else
rad=L+2
end
or
0<L & L<5
if L is a vector and
for L = 1:10
&nbsp
Yes, the evaluation of 0<L<5 is confusing. My quick search in the documentation failed. Anyhow, from left to right
0<L evaluates to true and true<5 evaluates to true because true is converted to 1, which is less than 5. I guess this is a legacy from the eigthies.

Categorie

Scopri di più su Multidimensional Arrays in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by