Azzera filtri
Azzera filtri

How to delete the columns that has NaN values?

87 visualizzazioni (ultimi 30 giorni)
Hi!
I have this 5x5 matrix. Of them, only column 2 and 3 does not contain any NaN values. How can I write down a code that will delete the entire column which even has only one NaN value?
1 2 3 4 5
NaN 6 7 8 11
4 8 9 1 NaN
NaN 4 0 2 8
NaN 1 6 NaN 9

Risposta accettata

Cris LaPierre
Cris LaPierre il 17 Ago 2022
I'd use rmmissing with the following syntax.
Since column correspond to the second dimension you would do this
A = [1 2 3 4 5
NaN 6 7 8 11
4 8 9 1 NaN
NaN 4 0 2 8
NaN 1 6 NaN 9];
R = rmmissing(A,2)
R = 5×2
2 3 6 7 8 9 4 0 1 6

Più risposte (0)

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!

Translated by