how can I delete empty elements of a cell?

1 次查看(过去 30 天)
suppose I have a cell c
c =
[]
[1x3 double]
[]
[]
[1x2 double]
and I want to delete all the empty elements in c and get
c =
[1x3 double]
[1x2 double]
how can I do this?

回答(2 个)

Walter Roberson
Walter Roberson 2013-3-12
c( cellfun( @isempty, c ) ) = [];
  2 个评论
may
may 2013-3-12
is this the same as
result = c(~cellfun('isempty',c))
?
Walter Roberson
Walter Roberson 2013-3-12
The form you gave will select the non-empty entries into "result" leaving everything in "c". The form I gave will delete the empty entries in "c" leaving "c" with no empty entries. Based on your showing "c =" in your question, what I gave is what you requested.

请先登录,再进行评论。


the cyclist
the cyclist 2013-3-12
c = c(not(cellfun(@isempty,c)))

类别

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

产品

Community Treasure Hunt

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

Start Hunting!

Translated by