Azzera filtri
Azzera filtri

IF condition with interval

185 visualizzazioni (ultimi 30 giorni)
Quantopic
Quantopic il 25 Ago 2014
Commentato: Ara Alexandrian il 10 Apr 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.

Risposta accettata

the cyclist
the cyclist il 25 Ago 2014
Modificato: the cyclist il 25 Ago 2014
You have to write it as two sub-conditions:
if (0<X) && (X<1)
  2 Commenti
Quantopic
Quantopic il 26 Ago 2014
Thanks a lot for help!
Ara Alexandrian
Ara Alexandrian il 10 Apr 2017
if (0<X && X<1)
...also works with multiple conditions.
-Cheers

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by