find most frequent characters in a string
显示 更早的评论
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?
采纳的回答
更多回答(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.
类别
在 帮助中心 和 File Exchange 中查找有关 Characters and Strings 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!