フィルターのクリア

Deleting missing values (different amount and distribution of NaNs for each column)

1 回表示 (過去 30 日間)
Peter P
Peter P 2017 年 12 月 20 日
コメント済み: Jos (10584) 2017 年 12 月 20 日
I have two matrices of the same size (17x82). Matrix A has no missing values. Matrix B has a different amount and distribution of NaNs for each column. I want to delete all missing values from matrix B as well as the values of matrix A that correspond to the NaNs of matrix B.
I tried: A_Without_NaN = A(~isnan(B)); However, reshaping does not work because the number of NaNs in matrix B varies for each column.
Any suggestions? Thanks in advance, Peter

採用された回答

Jos (10584)
Jos (10584) 2017 年 12 月 20 日
You cannot concatenate different length vectors into a single matrix. You could store each column of A into a separate cell
A_wn = arrayfun(@(k) A(~isnan(B(:,k)),k),1:size(A,2),'un',0)
% A_wn is a cell array. The k-th cell, A_wn{k}, holds the
% 'relevant' values of the k-th column of A
However, it might be preferred to leave the nans and use nan-specific functions like nansum and nanmean.
  2 件のコメント
Steven Lord
Steven Lord 2017 年 12 月 20 日
If you're using release R2015a or later, you can call sum and mean with the 'omitnan' parameter instead of calling nansum or nanmean. See the second item in the Mathematics section of the Release Notes for R2015a.
Jos (10584)
Jos (10584) 2017 年 12 月 20 日
Thanks Steven! I am getting old ...

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by