Counting repeated strings in an array
34 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
the cyclist
le 18 Nov 2014
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?
Réponses (1)
the cyclist
le 18 Nov 2014
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 commentaires
Voir également
Catégories
En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!