use of greater than and less than
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
per isakson
on 30 Aug 2014
Edited: per isakson
on 30 Aug 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 Comments
See Also
Categories
Find more on Multidimensional Arrays in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!