Removing all-NaN Rows/Columns from Cell Matrix?

2 ビュー (過去 30 日間)
John R.
John R. 2014 年 8 月 26 日
コメント済み: John R. 2014 年 8 月 26 日
Let's say I have the following cell matrix that contains NaN's, numbers, and strings...
A = {...
0 2 'All' NaN NaN 2
NaN NaN NaN NaN NaN NaN
NaN NaN 'Yes' NaN NaN 1};
Is there an easy way to identify the rows and columns that contain all NaN's? In this example, I would like to remove row 2, and then columns 4 and 5. The result would be...
B = {...
0 2 'All' 2
NaN NaN 'Yes' 1};
I have brute-forced it by checking every value, but I'm sure there is a more methodical approach using cellfun perhaps. My method took 30 lines but I'm guessing there it can be done in just a few lines.
Thanks!

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2014 年 8 月 26 日
A = { 0 2 'All' NaN NaN 2
NaN NaN NaN NaN NaN NaN
NaN NaN 'Yes' NaN NaN 1}
idx=cellfun(@(x) all(isnan(x)),A)
ii=all(idx,2)
jj=all(idx)
A(ii,:)=[]
A(:,jj)=[]
  1 件のコメント
John R.
John R. 2014 年 8 月 26 日
Worked like a charm, thanks!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by