any and all in an empty array should absolutely not give the same answers - the behavior of MATLAB is documented and correct.
any(A) means "there is an element A that is true," in other words
βxβA x is true
Since there are no elements in A , it correctly returns false .
all(A) means "for all elements in A , this element is true", in other words
βxβA x is true
This may be less intuitive, but since there are no elements in A , this sentence is true - and MATLAB correctly returns true . Any first-order logic tutorial will confirm this.
If you need a case where the behavior of MATLAB really seems wrong and inconsistent above, try
>> if [] disp('hello'); else disp('bye'); end bye
In all other cases, if X is true when all elements from X are true. But when X [] , if behaves differently. It is also documented.
source share