You can use the isnan
function in MATLAB to check whether a value or a matrix element is NaN
. If you want to check if a matrix contains only NaN
values, you can use the all
function along with isnan
function to evaluate whether all the elements of the matrix are NaN
. Here is an example code snippet:
main.m183 chars10 lines
In this example, all(isnan(A(:)))
tests all the elements of matrix A to evaluate whether they are NaN
or not. The (:)
operator is used to convert the matrix A to a column vector. If all elements of A are NaN
, then it will print 'All elements of A are NaN'. Otherwise, it will print 'A contains non-NaN elements'.
gistlibby LogSnag