Effacer les filtres
Effacer les filtres

Any idea why all([]) is true while any([]) is false

2 vues (au cours des 30 derniers jours)
Khaled Hamed
Khaled Hamed le 29 Juil 2012
>> all([])
ans =
1
>> any([])
ans =
0
  2 commentaires
Ryan
Ryan le 29 Juil 2012
It's written into the documentation as such, but no explanation is given.
Khaled Hamed
Khaled Hamed le 29 Juil 2012
I have just noticed the same with Nan! more confusing
>> all(nan)
ans =
1
>> any(nan)
ans =
0

Connectez-vous pour commenter.

Réponse acceptée

Daniel Shub
Daniel Shub le 29 Juil 2012
This post by Loren lead to some comments that address the issue, especially the one by Matt Fig.

Plus de réponses (1)

the cyclist
the cyclist le 29 Juil 2012
I can't say I know definitively, but I expect that one reason is for consistency when taking the union of sets with the empty set. For example, one would want
all(union(true,[]))
to be true, and also
any(union(false,[]))
to be false. The definitions in your question make sense in that context.
  1 commentaire
Khaled Hamed
Khaled Hamed le 29 Juil 2012
I have just noticed the same with NaN! more confusing
>> all(nan)
ans =
1
>> any(nan)
ans =
0

Connectez-vous pour commenter.

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