counting the duplicates

3 次查看(过去 30 天)
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

采纳的回答

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

更多回答(1 个)

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

类别

Help CenterFile Exchange 中查找有关 Data Types 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by