huffman.m

来自「EZW implementation which will use wavele」· M 代码 · 共 36 行

M
36
字号
function [encode_x,h,sortindex]=huffman(DD)

a=size(DD,2);

for i=1:a,
if   DD(i)=='p';
     D(i)=1;
end
if DD(i)=='n';
     D(i)=2;
end
if DD(i)=='z';
     D(i)=3;
end
if DD(i)=='t';
     D(i)=4;
end
end

f=frequency(D); %求元素出现的频率
[h,sortindex]=huffman_encode(f);
encode_x=[];
for i=1:a,
    if D(i)==1;
        encode_x=[encode_x,h(find(sortindex==1),1:4)];
    end
    if D(i)==2;
        encode_x=[encode_x,h(find(sortindex==2),1:4)];
    end
     if D(i)==3;
        encode_x=[encode_x,h(find(sortindex==3),1:4)];
    end
     if D(i)==4;
        encode_x=[encode_x,h(find(sortindex==4),1:4)];
    end
end

⌨️ 快捷键说明

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