IF condition with interval

47 vues (au cours des 30 derniers jours)
Quantopic
Quantopic le 25 Août 2014
Commenté : Ara Alexandrian le 10 Avr 2017
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.

Réponse acceptée

the cyclist
the cyclist le 25 Août 2014
Modifié(e) : the cyclist le 25 Août 2014
You have to write it as two sub-conditions:
if (0<X) && (X<1)
  2 commentaires
Quantopic
Quantopic le 26 Août 2014
Thanks a lot for help!
Ara Alexandrian
Ara Alexandrian le 10 Avr 2017
if (0<X && X<1)
...also works with multiple conditions.
-Cheers

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur 2-D and 3-D Plots 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!

Translated by