How can I remove columns that contain only NaNs from a cell array?

2 次查看(过去 30 天)
I have a cell array that contains NaNs. Some columns only contain NaNs. How can I detect these columns and remove them from the cell array? 

采纳的回答

MathWorks Support Team
% Create some data
A = {2, NaN, 3; NaN, NaN, 'text'; 5, NaN, 6};
% Create an anonymous function to detect NaNs
f = @(x) any(isnan(x));
% Detect where there are NaNs
B = cellfun(f, A);
% Now detect columns that contain ONLY NaNs
C = all(B);
% Remove these columns
A(:,C) = [];

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Cell Arrays 的更多信息

产品


版本

R2014a

Community Treasure Hunt

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

Start Hunting!

Translated by