remove rows that contain zeros from cells array in matlab
4 次查看(过去 30 天)
显示 更早的评论
I have a cell array resulted from a certain code as follows:
m =
[ 0] 'GO:0008150'
'GO:0008150' 'GO:0016740'
'GO:0016740' 'GO:0016787'
'GO:0016787' 'GO:0006810'
'GO:0008150' 'GO:0006412'
'GO:0016740' 'GO:0004672'
'GO:0016740' 'GO:0016779'
'GO:0016787' 'GO:0004386'
'GO:0016787' 'GO:0003774'
'GO:0016787' 'GO:0016298'
'GO:0006810' 'GO:0016192'
'GO:0006412' 'GO:0005215'
'GO:0004672' 'GO:0030533'
[ 0] 'GO:0008150'
[ 0] 'GO:0016740'
'GO:0008150' 'GO:0016787'
'GO:0008150' 'GO:0006810'
'GO:0006810' 'GO:0006412'
[ 0] 'GO:0004672'
[ 0] 'GO:0016779'
[ 0] 'GO:0004386'
'GO:0016192' 'GO:0003774'
[ 0] 'GO:0016298'
[ 0] 'GO:0016192'
'GO:0006810' 'GO:0005215'
'GO:0005215' 'GO:0030533'
I need to remove the rows which contains zero (for example: in the above cells array m, row one should be deleted because we have a zero in the first column). so how can I create an array from this array that doesn't contain zeros?
采纳的回答
更多回答(3 个)
Jan
2012-10-25
编辑:Jan
2012-10-25
If efficiency matters, it should be considered, than cellfun is slow when operating on anonymous functions. Functions handles are better, but the built-in string functions are really fast:
idx = cellfun('isclass', c, 'char');
c = c(idx, :);
What a pitty that TMW hides them in the documentation instead of mentioning their efficiency.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!