counting the duplicates

3 visualizzazioni (ultimi 30 giorni)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi il 22 Nov 2011
When I set
longwords={'banana';'milk';'butter';'cake';'lamb';'milk'}
no_duplicates=0;
for idup=1:length(longwords)
if ............ % so here in the cell i would like compare any string that are duplicates of each other and count them but im not sure how, can anybody tell me?Thank you.
no_duplicates=no_duplicates+1; end

Risposta accettata

Daniel Shub
Daniel Shub il 22 Nov 2011
How about:
length(longwords)-length(unique(longwords))

Più risposte (1)

Thomas
Thomas il 22 Nov 2011
longwords={'banana';'milk';'butter';'cake';'lamb';'milk'}
uniqueWords=numel(unique(longwords))
unique(longwords)
repeatedWords=numel(longwords)-numel(unique(longwords))
Hope this helps..

Categorie

Scopri di più su Cell Arrays in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by