% Example 2.32 in lecture note

pX = [0.4 0.3 0.1 0.1 0.06 0.04];       % pmf of X
SX = [1:length(pX)];                    % Source Alphabet
[dict,EL] = huffmandict(SX,pX);         % Create codebook

% Note that MATLAB gives a codebook which is not the same as the one we 
% chose to present in class. However, the expected length is the same.

%% Pretty print the codebook.
codebook = dict;
for i = 1:length(codebook)
    codebook{i,2} = num2str(codebook{i,2});
end
codebook

EL