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

 Respuesta aceptada

Walter Roberson
Walter Roberson el 12 de Oct. de 2011

41 votos

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

6 comentarios

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

Iniciar sesión para comentar.

Más respuestas (3)

Wayne King
Wayne King el 12 de Oct. de 2011

6 votos

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

0 votos

isnan()

1 comentario

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

Iniciar sesión para comentar.

Elizabeth Drybrugh
Elizabeth Drybrugh el 3 de Mayo de 2018
Editada: Elizabeth Drybrugh el 3 de Mayo de 2018

0 votos

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

Categorías

Etiquetas

Preguntada:

NS
el 12 de Oct. de 2011

Comentada:

el 22 de Nov. de 2021

Community Treasure Hunt

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

Start Hunting!

Translated by