How can I remove all rows from a matrix which contain NaN values?

1 Ansicht (letzte 30 Tage)

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]).

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 14 Nov. 2024
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 Kommentar
Walter Roberson
Walter Roberson am 14 Nov. 2024
A = [1, 2, 3; 4, NaN, 6; 7, 8, 9];
A = rmmissing(A)
A = 2×3
1 2 3 7 8 9
<mw-icon class=""></mw-icon>
<mw-icon class=""></mw-icon>

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Numeric Types finden Sie in Help Center und File Exchange

Produkte


Version

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by