필터 지우기
필터 지우기

How can I find the second and third, etc. most frequent character in say a list of words (cell array of strings)?

조회 수: 4 (최근 30일)
How can I find the second and third, etc. most frequent character in say a list of words (cell array of strings)?
I know how to find the most frequent in all words: mode(strjoin(dict,'')). However I know want to know how to find the second and third and fourth etc. Dict is my a list of words.

답변 (1개)

TastyPastry
TastyPastry 2015년 11월 5일
a = unique(myStr);
n = histc(myStr,a);
[n,idx] = sort(n);
myFreq = myStr(idx);
Now myFreq will be the unique characters sorted from highest occurring to lowest. The sorted vector n will give you the number of times a character appears in your string. This does assume you've already concatenated all the words using
strjoin(dict,'');
  댓글 수: 3
Zhimeng Wang
Zhimeng Wang 2020년 6월 15일
Could you elaborate on what each one means? For example, what is a, n, idx and myFreq respectively? Thank you!
Walter Roberson
Walter Roberson 2020년 6월 15일
a is the list of unique values in myStr
n is the count of the number of times each unique value in myStr occurs.
Then n is sorted into ascending order, and the sort order is recorded in idx
myFreq then uses the recorded sort order in order to sort the unique values into ascending order according to count.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by