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