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!