How can I remove all rows from a matrix which contain NaN values?
13 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 14 Nov 2024 alle 0:00
Commentato: Walter Roberson
il 14 Nov 2024 alle 6:01
How can I remove all rows from a matrix which contain NaN values?
For example:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
In matrix A defined above, I would like to remove row 2 ([4, NaN, 6]).
Risposta accettata
MathWorks Support Team
il 14 Nov 2024 alle 0:00
Use the following code to remove all rows which contain NaN values from a matrix A:
>> A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
>> A = A(~any(isnan(A), 2), :);
1 Commento
Walter Roberson
il 14 Nov 2024 alle 6:01
A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
A = rmmissing(A)
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Numeric Types in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!