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

 Risposta accettata

Walter Roberson
Walter Roberson il 12 Ott 2011
[row, col] = find(isnan(YourMatrix));

6 Commenti

Wayne King
Wayne King il 12 Ott 2011
@Walter Now, that's a better way :)
NS
NS il 12 Ott 2011
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 :(
Whitney
Whitney il 22 Nov 2021
An empty result means that there are no NaNs in the martix

Accedi per commentare.

Più risposte (3)

Wayne King
Wayne King il 12 Ott 2011
One way:
X = ones(10,4);
X(3,4) = NaN;
indices = find(isnan(X) == 1);
[I,J] = ind2sub(size(X),indices);
bym
bym il 12 Ott 2011
isnan()

1 Commento

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

Accedi per commentare.

Elizabeth Drybrugh
Elizabeth Drybrugh il 3 Mag 2018
Modificato: Elizabeth Drybrugh il 3 Mag 2018
Do this to get the sum
sum(isnan(x))
For other functions, it depends on what you actually need....

Tag

Richiesto:

NS
il 12 Ott 2011

Commentato:

il 22 Nov 2021

Community Treasure Hunt

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

Start Hunting!

Translated by