Finding NaNs in cell array.
Ältere Kommentare anzeigen
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 Kommentar
Pruthvi G
am 12 Mär. 2020
Data(cellfun(@(cell) any(isnan(cell(:))),Data))={''};
Antworten (3)
Fangjun Jiang
am 20 Mai 2016
Data_text={'Speed' 'Load' [NaN] 'Sample'};
index=cellfun(@isnan,Data_text,'uni',false);
index=cellfun(@any,index);
Data_text(index)=[];
2 Kommentare
Rajesh Patel
am 20 Mai 2016
Fangjun Jiang
am 20 Mai 2016
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
am 20 Mai 2016
Data_text={'Speed' 'Load' nan 'Sample'}
Data_text(:,cellfun(@(x) any(isnan(x)),Data_text(1,:)))=[]
Pruthvi G
am 12 Mär. 2020
Data(cellfun(@(cell) any(isnan(cell(:))),Data))={''};
Kategorien
Mehr zu Matrix Indexing finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!