Counting repeated strings in an array

조회 수: 34 (최근 30일)
Md Mamun Reaz
Md Mamun Reaz 2014년 11월 18일
답변: the cyclist 2014년 11월 18일
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
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
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));

카테고리

Help CenterFile Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by