shamalaia
shamalaia

Reputation: 2347

numel(isnan(A)) == numel(~isnan(A)) == numel(A)?

I have a 121x601 matrix with some NaN values.

I cannot understand the reason of the following inconsistency:

>> size(A,1)*size(A,2)

ans =

       72721

>> numel(~isnan(A))

ans =

       72721

>> numel(isnan(A))

ans =

       72721

Can anybody point it to me, please?

Upvotes: 1

Views: 356

Answers (1)

ale64bit
ale64bit

Reputation: 6242

numel returns the number of elements of the matrix, independently of what they are. isnan(A) transforms each element in A to a boolean, depending if the corresponding element is NaN or not. But both matrices isnan(A) and its complement ~isnan(A) have the same number of elements, namely, the number of elements of the original matrix, A.

See more about numel and isnan.

Upvotes: 4

Related Questions