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])
;

回答(1 个)

Sid Singh
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.
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);

类别

Help CenterFile Exchange 中查找有关 Histograms 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by