getting rid of empty cells in a cell array
31 次查看(过去 30 天)
显示 更早的评论
Hi,
can you please help me with this? I have the following cell array
x = {1,[],'ciao',[],[]};
I want to exclude the empty cells, and get another array like this:
y = {1,'ciao'};
Thank you!
0 个评论
采纳的回答
Niklas Nylén
2014-1-15
First, check which cells that are empty using the function isempty. Since isempty does not accept cell arrays as input, you can use the cellfun function. This will call a function with each element of a cell array:
index = cellfun(@isempty, x) == 0;
y = x(index)
更多回答(1 个)
Mischa Kim
2014-1-15
编辑:Mischa Kim
2014-1-15
Try y=x(~cellfun('isempty',x))
4 个评论
Yiqian Qian
2021-5-27
I have the same question above, how to apply this to a specific row or colums.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Structures 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!