find most frequent characters in a string
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a string and I want to find the most frequent characters that appear in it. Is there anyway to do this with matlab?
댓글 수: 0
채택된 답변
Walter Roberson
2011년 12월 13일
mode()
댓글 수: 3
Walter Roberson
2011년 12월 13일
David's code is fine. It could also be written more concisely as
char(mode(0+str))
추가 답변 (1개)
David Young
2011년 12월 13일
One way to get the commonest n characters, in descending order of frequency:
>> str = 'hello world';
>> n = 5; % number of characters to report
>> [~, c] = sort(hist(double(str), 0:255), 'descend');
>> f = char(c(1:n)-1)
f =
lo de
There may well be numerous better ways.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Characters and Strings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!