NaN selective removal from a matrix

2 vues (au cours des 30 derniers jours)
Ziv Kassner
Ziv Kassner le 9 Juil 2014
I have a matrix like this: a=[NaN NaN NaN NaN;NaN NaN NaN NaN;2 3 NaN 4;9 4 NaN 4;3 9 NaN 3];
and i want to remove all the rows that contains only NaN's to: b=[2 3 NaN 4;9 4 NaN 4;3 9 NaN 3];
please help me,
Ziv.

Réponse acceptée

Jos (10584)
Jos (10584) le 9 Juil 2014
tf1 = isnan(a)
tf2 = all(a,2)
tf3 = ~tf2
b = a(tf3,:)
b2 = a(~all(isnan(a),2),:) % in one giant leap
  1 commentaire
Ziv Kassner
Ziv Kassner le 9 Juil 2014
Great! worked perfectly!

Connectez-vous pour commenter.

Plus de réponses (1)

Andrei Bobrov
Andrei Bobrov le 9 Juil 2014
b = a(any(a == a,2),:);

Catégories

En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by