IF condition with interval

I want to have a script that runs if the variable X is within 0 and 1. I writed down the following code:
if 0 < X < 1
statement
else display(NaN)
end
The output script isn't an error but the if condition is not respected and values are away from the interval.
How can I solve this problem. Thanks in advance.

 采纳的回答

the cyclist
the cyclist 2014-8-25
编辑:the cyclist 2014-8-25
You have to write it as two sub-conditions:
if (0<X) && (X<1)

2 个评论

Thanks a lot for help!
if (0<X && X<1)
...also works with multiple conditions.
-Cheers

请先登录,再进行评论。

更多回答(0 个)

类别

帮助中心File Exchange 中查找有关 Entering Commands 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by