Eliminate Nan row in a large matrix

1 vue (au cours des 30 derniers jours)
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI le 17 Sep 2024
Hello,
I have a very large matrix where some elements are Nan.
I would like to delete the rows containing the these elements.
Example
For
A=[1 2 3; 2 4 Nan; 4 5 6; nan 9 0];
Output:
A=[1 2 3];
Any ideas?
Thank you
  1 commentaire
NAFTALI HERSCOVICI
NAFTALI HERSCOVICI le 17 Sep 2024
Déplacé(e) : Star Strider le 17 Sep 2024
Thank you all

Connectez-vous pour commenter.

Réponse acceptée

Voss
Voss le 17 Sep 2024
A(any(isnan(A),2),:) = [];

Plus de réponses (1)

Manish
Manish le 17 Sep 2024
Modifié(e) : Manish le 17 Sep 2024
Hi ,
I understand that you want that eliminate NaN rows in the matrix,we can achive this with help of ‘isnan’ function.
Here is the code example:
A = [1 2 3; 2 4 NaN; 4 5 6; NaN 9 0];
% Find rows with any NaN values
rowsWithNaN = any(isnan(A), 2);
% Keep only rows without NaN values
A = A(~rowsWithNaN, :);
% Display the result
disp(A)
1 2 3 4 5 6
Hope it helps!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by