use of greater than and less than
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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?
0 Commenti
Risposte (1)
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
 
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.
0 Commenti
Vedere anche
Categorie
Scopri di più su Multidimensional Arrays in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!