counting the duplicates

2 views (last 30 days)
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi on 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

Accepted Answer

Daniel Shub
Daniel Shub on 22 Nov 2011
How about:
length(longwords)-length(unique(longwords))
  1 Comment
NUR KHAIRUNNISA rahimi
NUR KHAIRUNNISA rahimi on 22 Nov 2011
yup, i used exactly this one!thank you!

Sign in to comment.

More Answers (1)

Thomas
Thomas on 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..

Tags

Community Treasure Hunt

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

Start Hunting!