Effacer les filtres
Effacer les filtres

Logical -1 = Logical 1?

4 vues (au cours des 30 derniers jours)
Diego
Diego le 13 Nov 2012
Dear all, While reviewing a code I found the following expression:
assert(fid ~= -1, etc
By checking the logical operators I found that for a true condition the number is 1.
I would like to ask if in Matlab applies the same rule than for other packages where any non-zero value is true.
Thanks,
Diego

Réponse acceptée

Matt Fig
Matt Fig le 13 Nov 2012
Modifié(e) : Matt Fig le 13 Nov 2012
Yes:
logical([-1 0 1 20 -10 .001 eps ])
The exception is NaN. NaN is non-zero, yet cannot be converted to logical. Try to do it and see what you get!
  2 commentaires
Diego
Diego le 13 Nov 2012
Thank you Matt.
Regards,
Diego
Daniel Shub
Daniel Shub le 14 Nov 2012
I think i is also an exception in that it is neither true nor false.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical 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