IF condition with interval

185 次查看(过去 30 天)
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 个评论
Quantopic
Quantopic 2014-8-26
Thanks a lot for help!
Ara Alexandrian
Ara Alexandrian 2017-4-10
if (0<X && X<1)
...also works with multiple conditions.
-Cheers

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Get Started with MATLAB 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by