フィルターのクリア

Finding NaNs in cell array.

30 ビュー (過去 30 日間)
Rajesh Patel
Rajesh Patel 2016 年 5 月 20 日
回答済み: Pruthvi G 2020 年 3 月 12 日
I create a cell array by importing some data (text and empty cells) from excel. It looks like this.. "Data_text =
Columns 1 through 7
'Speed' 'Load' [NaN] 'Sample' 'Calgen_Model' 'DOE_BSNOx' 'DOE_Pmax'
I want to find columns which contains NaN (from empty cells in excel) and delete those columns. I tried following but it does not seems to work.
Column_Names = cell2table(Data_text);
a = cellfun(@isnan,Data_text);
Thanks,
  1 件のコメント
Pruthvi G
Pruthvi G 2020 年 3 月 12 日
Data(cellfun(@(cell) any(isnan(cell(:))),Data))={''};

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

回答 (3 件)

Fangjun Jiang
Fangjun Jiang 2016 年 5 月 20 日
Data_text={'Speed' 'Load' [NaN] 'Sample'};
index=cellfun(@isnan,Data_text,'uni',false);
index=cellfun(@any,index);
Data_text(index)=[];
  2 件のコメント
Rajesh Patel
Rajesh Patel 2016 年 5 月 20 日
Thanks seems to be working. But I have couple of questions if you do not mind.
  1. # What does the line "index=cellfun(@any,index);" do?
  2. # Now if in the original array of "Data_text" had multiple rows and if I wanted to find NaN only in 1st row and delete columns corresponding to it, what modification to code need to be done?
Again, Thanks for quick answer.
Fangjun Jiang
Fangjun Jiang 2016 年 5 月 20 日
Data_text={'a','b', nan ,'c';1,2,3,4};
index=cellfun(@isnan,Data_text(1,:),'uni',false);
index=cellfun(@any,index);
Data_text(:,index)=[];
The first index is still a cell array. Use cellfun(@any,...) to get the logical index. Type "help any" to find the info for the any() function.

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


Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 20 日
Data_text={'Speed' 'Load' nan 'Sample'}
Data_text(:,cellfun(@(x) any(isnan(x)),Data_text(1,:)))=[]

Pruthvi G
Pruthvi G 2020 年 3 月 12 日
Data(cellfun(@(cell) any(isnan(cell(:))),Data))={''};

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by