How to get a new cell array containing the repeated elements in an original cell?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
YU ZHU
am 15 Nov. 2017
Kommentiert: YU ZHU
am 15 Nov. 2017
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 Kommentare
Akzeptierte Antwort
Andrei Bobrov
am 15 Nov. 2017
Bearbeitet: Andrei Bobrov
am 15 Nov. 2017
[g,val] = findgroups(celloriginal);
out = val(histcounts(g,1:max(g)+1)>1);
or
[a,~,c] = unique(celloriginal);
out = a(accumarray(c,1)>1);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!