How to get a new cell array containing the repeated elements in an original cell?
2 次查看(过去 30 天)
显示 更早的评论
For example if I have an original cell as
celloriginal={'apple','bird','cat','bird','zoo','bird','cat'};
and I want to obtain a new cell which contains the elements, 'bird' and 'cat', that appear multiple times in the original cell
cellnew={'bird','cat'}
I have tried unique(celloriginal), but got no clue what to do next. Help would be really appreciated.
0 个评论
采纳的回答
Andrei Bobrov
2017-11-15
编辑:Andrei Bobrov
2017-11-15
[g,val] = findgroups(celloriginal);
out = val(histcounts(g,1:max(g)+1)>1);
or
[a,~,c] = unique(celloriginal);
out = a(accumarray(c,1)>1);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!