Filtering Columns of Array by Number of Row Contents

1 vue (au cours des 30 derniers jours)
Justin Delano
Justin Delano le 27 Mar 2020
Commenté : Ameer Hamza le 2 Avr 2020
I have arrays that look like this:
A =
1 NaN NaN
2 3 4
2 5 NaN
I want to remove columns that contain rows with less than n non-NaN entries. In this case, with n=2, the first column of A would be removed, since the first row contains only 1 non-NaN value. Is there a compact way to do this? I hope this explanation makes sense!

Réponse acceptée

Ameer Hamza
Ameer Hamza le 27 Mar 2020
Modifié(e) : Ameer Hamza le 27 Mar 2020
A = [1 NaN NaN
2 3 4
2 5 NaN];
n = 2;
A(sum(~isnan(A), 2) < n, :) = [];
Result
A =
2 3 4
2 5 NaN
  16 commentaires
Justin Delano
Justin Delano le 2 Avr 2020
That looks good! Thank you so much!
Ameer Hamza
Ameer Hamza le 2 Avr 2020
Glad to be of help.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur NaNs dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by