why won't this work?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
I want this code to read a text file, convert it to ASCII Characters, make a pie chart over the ten most occurring numbers, be able to change for instance an "a" to "c" (two steps) and the program to make two steps everywhere in the text and then print the new text.
Will be very grateful for your help!
fid=fopen('krypterad1.txt','rt');%Open text file
text = fscanf(fid,'%c',Inf);%Read text file
text = upper(text);%Convert to upper cases
nummer = double(text);%Convert text to Ascii
n = histc(nummer, 65:90);
for nummer =65:90;
for antal=1:n
end
end
[B,IX] = sort(n, 'descend');%Sort array B in descending order
fprintf('%d\n',B);%Print array B
pie(B(1,10)')%Make pie chart of the ten most occuring numbers in the array (doesn't work)
title('De 10 mest förekommande bokstäverna i texten')%Chart title
f = input('byt från ','s')
t = input('till ','s')
diff = double(t) - double(f)
for rulla = nummer-(diff)
if rulla<=64, rulla=rulla+26; end
if rulla>90, rulla=rulla-26; end
okodadtext = char(rulla);
fprintf('%s',okodadtext)
end
0 Kommentare
Antworten (1)
Charu
am 29 Jan. 2025
Hello, Henrick
According to my understanding you are trying to create a pie chart displaying the top 10 most frequent characters from your dataset, it's important to sort the characters based on their frequencies. In the code provided, the histc function was used to calculate these frequencies. However, it is worth noting that histc is an older function and its use is now discouraged. In the latest version, it is recommended to use the histcounts function, which offers enhanced functionality and is more up-to-date.
Below is a code snippet demonstrating how to achieve this using histcounts:
% Calculate the histogram of letter frequencies (A-Z)
frequencies = histcounts(nummer, 64.5:1:90.5);
In this example, histcounts function is employed to compute the frequency of each letter from 'A' to 'Z'. The function achieves this by specifying the ASCII range from 65 to 90, ensuring accurate frequency calculation.
For further details on the histcounts function, refer to the following MathWorks documentation:
Additionally, for more information on why the use of histc is discouraged, you may consult the relevant documentation, you can refer to this part of the documentation.
Hope this is beneficial!
0 Kommentare
Siehe auch
Kategorien
Mehr zu Data Distribution Plots finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!