Reputation: 335
I have a matrix <1x100>
. How do I check if all the values in the matrix are NaN?
Basically I want to check if the matrix only contains of NaN values with an if-statement.
Upvotes: 1
Views: 2997
Reputation: 1492
Lets consider x which is a vector of nan
x = nan(1,100);
to check if all the values are nan , you can do
if(~isempty(find(isnan(x))))
Upvotes: -1
Reputation: 5822
Solution
Use the following syntax:
res = ~any(~isnan(X(:)));
if res==true it means that that the matrix contains only nan values.
Example
X = nan(3,3)
~any(~isnan(X(:)))
X(1,2) = 0;
~any(~isnan(X(:)))
Results
ans = 1
ans = 0
Upvotes: 4