delete the columns with the last two values equal to NAN
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Qian cao
am 21 Dez. 2015
Bearbeitet: Image Analyst
am 21 Dez. 2015
Hi all, I have a matrix
a=[1 NaN 1 1; 1 1 1 1; NaN NaN NaN 1;NaN NaN 1 NaN ]
How to do the function that deletes the columns whose last two values are NaN? So the a matrix here is expected to be
b=[1 1; 1 1; NaN 1; 1 NaN ]
after the first and second column are deleted from the matrix.
a =
1 NaN 1 1
1 1 1 1
NaN NaN NaN 1
NaN NaN 1 NaN
b =
1 1
1 1
NaN 1
1 NaN
Thank you very much.
0 Kommentare
Akzeptierte Antwort
Renato Agurto
am 21 Dez. 2015
This should do it:
b = a(:, ~isnan(a(end-1,:)) | ~isnan(a(end,:)));
1 Kommentar
Guillaume
am 21 Dez. 2015
Alternatively,
b = a(:, ~all(isnan(a(end-1:end, :))));
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Creating and Concatenating Matrices finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!