huff.m

来自「huffman coding using matlab programming」· M 代码 · 共 35 行

M
35
字号
function huff()
clc;
fid=fopen('seq1.txt','r');
seq=fread(fid,'*char');
fclose(fid);
seq=reshape(seq,1,length(seq));
[alpha prob]=probmodel(seq);
if ~isempty(alpha)
[huf entropy avglength redundancy]=huffman(alpha,prob);
if ~isempty(huf)
    lp=length(prob);
   for i=1:lp
     str=huf(i).sym;
     str=strcat(str,' :');
     str=strcat(str,num2str(huf(i).prob));
     str=strcat(str,' :');
     str=strcat(str,huf(i).code);
     disp(str);
   end
   disp(strcat('Entropy = ',num2str(entropy)));
   disp(strcat('Average length = ',num2str(avglength)));
   disp(strcat('Redundancy = ',num2str(redundancy)));
   encseq=huffencode(huf,seq);
   disp('Sequence :');
   disp(seq);
   disp('Encoded Sequence :');
   disp(encseq);
   decseq=huffdecode(huf,encseq);
   disp('Decoded Sequence :');
   disp(decseq);
end
else
    display('Empty Sequence....');
end
end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?