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

 採用された回答

Walter Roberson
Walter Roberson 2011 年 10 月 12 日

41 投票

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

6 件のコメント

Wayne King
Wayne King 2011 年 10 月 12 日
@Walter Now, that's a better way :)
NS
NS 2011 年 10 月 12 日
Works fine. Thanks Walter. :)
Jaspalsingh Virdi
Jaspalsingh Virdi 2018 年 8 月 16 日
Thanks for a quick help even my data was too lARGE
Anirban Mandal
Anirban Mandal 2020 年 3 月 19 日
thanks for providing an efficient solution
Ana Paulina García
Ana Paulina García 2020 年 10 月 5 日
for me this actually creates a 1x0 variable named row and another one named col. None of the variables tells me the index :(
Whitney
Whitney 2021 年 11 月 22 日
An empty result means that there are no NaNs in the martix

サインインしてコメントする。

その他の回答 (3 件)

Wayne King
Wayne King 2011 年 10 月 12 日

6 投票

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

0 投票

isnan()

1 件のコメント

NS
NS 2011 年 10 月 12 日
This gives me just an array of 0 and 1. I need more precise info :(

サインインしてコメントする。

Elizabeth Drybrugh
Elizabeth Drybrugh 2018 年 5 月 3 日
編集済み: Elizabeth Drybrugh 2018 年 5 月 3 日

0 投票

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

カテゴリ

タグ

質問済み:

NS
2011 年 10 月 12 日

コメント済み:

2021 年 11 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by