I know I can use isnan to check for individual elements, such as
for i=1:m
for j=1:n
if isnan(A(i,j))
do something
end
end
end
However, instead what I want to do is
if any(isnan(A))
do something
end
When I tried to do this, it doesn’t go into the argument because it is considered false. If I just type any(isnan(A)), I just get 1 0 1.
So how do I do this?
Since
Awas a matrix,isnan(A)is also a matrix andany(isnan(A))is a vector, whereas theifstatement really wants a scalar input. Using the(:)notation flattensAinto a vector, regardless of the initial size.