필터 지우기
필터 지우기

how to find the most used letters in a text?

조회 수: 1 (최근 30일)
Armina Petrean
Armina Petrean 2023년 4월 3일
답변: Alexander 2023년 4월 3일
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.

답변 (2개)

Cris LaPierre
Cris LaPierre 2023년 4월 3일

Alexander
Alexander 2023년 4월 3일
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);

카테고리

Help CenterFile Exchange에서 Data Import and Export에 대해 자세히 알아보기

태그

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by