finding most common letter in a bunch of words
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Max
el 10 de Nov. de 2015
Comentada: Guillaume
el 10 de Nov. de 2015
say I have a bunch of words
x={'abac';'abaca';'abacate';'abacay';'abacinate';'abacination';'abaciscus'}
What would I write to find the most common letter in x so for example Most_common_letter=%most common letter that appears in x
0 comentarios
Respuesta aceptada
Más respuestas (2)
Guillaume
el 10 de Nov. de 2015
Two steps are required:
- build the histogram of the letters, however you want (using accumarray, histc or histcounts)
- find the max of the histogram
x = {'abac';'abaca';'abacate';'abacay';'abacinate';'abacination';'abaciscus'};
[letter, ~, pos] = unique([x{:}]);
letterhist = accumarray(pos, 1); %letter histogram
[~, maxidx] = max(letterhist);
fprintf('the most frequent letter is: %c\n', letter(maxidx));
2 comentarios
Guillaume
el 10 de Nov. de 2015
The printing was just for demo. Getting the letter is there right in the code:
letter(maxidx)
Ver también
Categorías
Más información sobre File Operations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!