and if in matlab?
2 次查看(过去 30 天)
显示 更早的评论
Hi,
I want to run an if loop with 2 conditions, but I can't see an "and-if" equivalent.
Eg:
if 0<x<1
*and y2<y1*
z=y2;
else
end
What operator can I use instead of and?
Thanks,
Richard
采纳的回答
更多回答(1 个)
Walter Roberson
2011-4-8
0<x<1 does not do what you want it to!! It is parsed as
(0<x)<1 . 0<x returns a boolean value, 0 or 1, and then that value is tested according to whether it is < 1 which is only the case if the operation was false. The code is thus equivalent to
~(0<x)
and so is the same as
isnan(x) || 0 >= x
I doubt that you would want 0<x<1 to be true when x is nan !!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!