MATLAB: Simple Method for Finding if ANY NaN values occur in a matrix.

arrayinfinitiesMATLABmatrixnan'svector

Is there a quick method of finding out whether or not a matrix or a vector in matlab has any NaN values? A large matrix filled with mostly 0's (after applying isnan(MATRIX)) does not really cut it.
Don't get me wrong, I would information of finding out where such NaN's occur and how to count how many NaN values appear in a given matrix, but I really would like to know if there is a simple way to identify if any NaN's at all appear in a given matrix with a simple 1 or 0 response, as it would save me time having to inspect the matrix or write a program to do it.
Would there be simple ways of counting how many NaN's occur, and identify their location in a given matrix? I assume such techniques would be applicable to finding infinities as well, am I correct?

Best Answer

Short of a mex routine that can avoid the creation of a potentially large intermediate array, I think you are stuck with isnan( ). E.g., counting the number of NaN's
result = sum(isnan(MATRIX(:)));
Or if you want locations, then find( ) etc.
And yes, you can do similar calculations with the isinf( ) function.
A mex routine to do this would not be too difficult to write, btw ...