How can I remove columns that contain only NaNs from a cell array?
2 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2014-6-10
回答: MathWorks Support Team
2014-6-10
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
2014-6-10
% 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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Cell Arrays 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!