Find NaN elements in a matrix

Hi Guys,
How can I find the exact location of NaN elements in a matrix. I work with really large arrays (size 1500*200).
How can I find which row has a NaN value in a column matrix or vice versa.?
Thanks
N

 采纳的回答

[row, col] = find(isnan(YourMatrix));

6 个评论

@Walter Now, that's a better way :)
Works fine. Thanks Walter. :)
Thanks for a quick help even my data was too lARGE
thanks for providing an efficient solution
for me this actually creates a 1x0 variable named row and another one named col. None of the variables tells me the index :(
An empty result means that there are no NaNs in the martix

请先登录,再进行评论。

更多回答(3 个)

One way:
X = ones(10,4);
X(3,4) = NaN;
indices = find(isnan(X) == 1);
[I,J] = ind2sub(size(X),indices);
isnan()

1 个评论

This gives me just an array of 0 and 1. I need more precise info :(

请先登录,再进行评论。

Do this to get the sum
sum(isnan(x))
For other functions, it depends on what you actually need....

类别

在 帮助中心 和 File Exchange 中查找有关 Logical 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by