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.
3 次查看(过去 30 天)
显示 更早的评论
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])
;
0 个评论
回答(1 个)
Sid Singh
2019-10-21
编辑:Sid Singh
2019-10-21
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!