use of greater than and less than
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (1)
per isakson
le 30 Août 2014
Modifié(e) : per isakson
le 30 Août 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 commentaires
Voir également
Catégories
En savoir plus sur Multidimensional Arrays dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!