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

 Akzeptierte Antwort

Walter Roberson
Walter Roberson am 12 Okt. 2011

41 Stimmen

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

6 Kommentare

Wayne King
Wayne King am 12 Okt. 2011
@Walter Now, that's a better way :)
NS
NS am 12 Okt. 2011
Works fine. Thanks Walter. :)
Jaspalsingh Virdi
Jaspalsingh Virdi am 16 Aug. 2018
Thanks for a quick help even my data was too lARGE
Anirban Mandal
Anirban Mandal am 19 Mär. 2020
thanks for providing an efficient solution
Ana Paulina García
Ana Paulina García am 5 Okt. 2020
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 am 22 Nov. 2021
An empty result means that there are no NaNs in the martix

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (3)

Wayne King
Wayne King am 12 Okt. 2011

6 Stimmen

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

0 Stimmen

isnan()

1 Kommentar

NS
NS am 12 Okt. 2011
This gives me just an array of 0 and 1. I need more precise info :(

Melden Sie sich an, um zu kommentieren.

Elizabeth Drybrugh
Elizabeth Drybrugh am 3 Mai 2018
Bearbeitet: Elizabeth Drybrugh am 3 Mai 2018

0 Stimmen

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

Tags

Gefragt:

NS
am 12 Okt. 2011

Kommentiert:

am 22 Nov. 2021

Community Treasure Hunt

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

Start Hunting!

Translated by