Filtering Columns of Array by Number of Row Contents

1 次查看(过去 30 天)
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!

采纳的回答

Ameer Hamza
Ameer Hamza 2020-3-27
编辑:Ameer Hamza 2020-3-27
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 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 NaNs 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by