フィルターのクリア

Remove rows or cols whose elements are all NaN

4 ビュー (過去 30 日間)
Jeon
Jeon 2013 年 4 月 2 日
I have a matrix A:
A = [1 2 3 4 NaN;
NaN NaN NaN NaN NaN;
1 2 NaN 4 5;
1 NaN 3 4 5];
and what I just want to is:
A = [1 2 3 4 NaN;
1 2 NaN 4 5;
1 NaN 3 4 5];
Currently I'm using the follwoing:
method = 1;
A = A'; % transposing is just for convenience
if method == 1
A = A(:, ~isnan(nanmean(A))); % nanmean throws NaN if all elements are NaN
elseif method == 2
A = A(:, sum(~isnan(A)) ~= 0);
end
A = A'; % re-transpose
However, I think nanmean is for statistical purpose and not for matrix manipulation. Moreover, actually I have much much much larger matrix. Thus, such operation might require longer computational time.
And I don't think all(isnan(A)) or all(~isnan(A)) is appropriate in some special cases.

採用された回答

José-Luis
José-Luis 2013 年 4 月 2 日
your_mat = A(all(isnan(A),2),:);

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDescriptive Statistics についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by