Counting repeated strings in an array
34 次查看(过去 30 天)
显示 更早的评论
Hi all,
I have an array like below
B b Bb C c Cc A D a AB bD DC ca ABb BbD bDC DCc Cca ABbD BbDC bDCc DCca ABbDC BbDCc bDCca ABbDCc BbDCca ABbDCca BC Cb BCb d aB bd caB aBC Cbd CcaB caBC aBCb BCbd DCcaB CcaBC caBCb aBCbd DCcaBC CcaBCb caBCbd DCcaBCb CcaBCbd DCcaBCbd dc bdc Cbdc AD Da ADa BA Ad DaB aBA BAd DaBA aBAd DaBAd da Ada ab dab BAda Adab BAdab
Now I wanted to see the unique values as well as their corresponding repeated values without sorting the aray. For example:
Output will be unique('A','stable') and their occurance
Thank you
1 个评论
the cyclist
2014-11-18
Is it one long string, with spaces, like
S = 'B b Bb C and so on'
or is it a cell array
S = {'B','b','Bb','C', and so on}
or something else?
回答(1 个)
the cyclist
2014-11-18
I think you can use the third output of unique, along with the hist function:
[uniqueS,~,idx] = unique(S,'stable');
count = hist(idx,unique(idx));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!