How to Plot a histogram of the letter frequency from the encoding key? I can get my histogram to show me the ascii values of each letter that comes up but can't figure out how to get it to display the characters instead of ascii vals.
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Noah Hudson
el 18 de Oct. de 2019
Comentada: Felipe Bachion de Santana
el 15 de Mzo. de 2021
function Project2(symbols,Dictionary)
%probability vector goes in the dictionary
% symbols go in the transmitter
%tf = ischar(symbols)
%if tf == 1
[dict,avglen] = huffmandict(num2cell(symbols), Dictionary); %creates a 1x6 cell array for transmitter to create huffmandict
sig = char( randsrc(1,10,[double(symbols); Dictionary]) ); %creates a signal from the probabilities of the Dictionary with random order
encoded = huffmanenco(sig,dict) %occurence of symbol is based on Dictionary
decoded = cell2mat(huffmandeco(encoded,dict))
z = isequal(sig,decoded)
%else
% [dict, avglen] = huffmandict(symbols,Dictionary);
% sig = randsrc(1,10,[symbols; Dictionary]);
% comp = huffmanenco(sig,dict);
% dsig = huffmandeco(comp,dict);
% isequal(sig,dsig);
% end
% the for loop below gives a binary key for each letter assigned
temp = dict;
for k = 1:length(temp)
temp{k,2} = num2str(temp{k,2});
end
%Y = categorical(dict)
G = double(decoded) %this is histogram of ascii values
histogram(G);
%histogram(Y);
dictionary.Symbols = symbols
dictionary.Probabilities = Dictionary
dictionary.averagelength = avglen
dictionary.encoded = encoded
dictionary.decoded = decoded
dictionary.Binarykey = temp
end
% function call Project2(['abcdef'],[.4,.15,.05,.15,.05,.2])
;![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243250/image.png)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/243250/image.png)
0 comentarios
Respuestas (1)
Sid Singh
el 21 de Oct. de 2019
Editada: Sid Singh
el 21 de Oct. de 2019
Hi, it is expected if you use numeric values to plot the histogram. You can use categorical array to achieve what you want to do.
https://www.mathworks.com/help/matlab/ref/matlab.graphics.chart.primitive.histogram.html#buhzm_z-1-C
for k = 1:length(decoded)
c_arr{k} = char(decoded(k));
end
categ_arr = categorical(c_arr);
%G = double(decoded); %this is histogram of ascii values
histogram(categ_arr);
2 comentarios
Ver también
Categorías
Más información sobre Histograms 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!