Effacer les filtres
Effacer les filtres

Find NaN elements in a matrix

632 vues (au cours des 30 derniers jours)
NS
NS le 12 Oct 2011
Commenté : Whitney le 22 Nov 2021
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

Réponse acceptée

Walter Roberson
Walter Roberson le 12 Oct 2011
[row, col] = find(isnan(YourMatrix));
  6 commentaires
Ana Paulina García
Ana Paulina García le 5 Oct 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 le 22 Nov 2021
An empty result means that there are no NaNs in the martix

Connectez-vous pour commenter.

Plus de réponses (3)

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

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

Connectez-vous pour commenter.


Elizabeth Drybrugh
Elizabeth Drybrugh le 3 Mai 2018
Modifié(e) : Elizabeth Drybrugh le 3 Mai 2018
Do this to get the sum
sum(isnan(x))
For other functions, it depends on what you actually need....

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by