Borrar filtros
Borrar filtros

how to find the most used letters in a text?

1 visualización (últimos 30 días)
Armina Petrean
Armina Petrean el 3 de Abr. de 2023
Respondida: Alexander el 3 de Abr. de 2023
I have a notepad file eith a literary text and i need to find the most used letters . How many times theey appear in that text.

Respuestas (2)

Cris LaPierre
Cris LaPierre el 3 de Abr. de 2023

Alexander
Alexander el 3 de Abr. de 2023
Try "help fread" and have a look on the examples. But anyway, this might help:
fid = fopen("PutYourTextInHere.txt", 'r');
c = fread(fid, inf, 'uint8')';
for (m = 48:126) % I think this is enough, but you can widen it to 1:255, I think
Chars(m) = length(find(c == m));
end
CharsInText = find(Chars > 0);
for n = 1: length(CharsInText)
fprintf('Character = %s exists %i times\n', char(CharsInText(n)), Chars(CharsInText(n)))
end
fclose(fid);

Categorías

Más información sobre Data Import and Export en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by