資源簡介
lz編碼用的很廣泛,用matlab實現lz編碼很簡單,而且實用

代碼片段和文件信息
function?[entropy]=Entropy(seq)
%the?function?that?calculate?the?source?entropy
alpha(1)=seq(1);
prob(1)=1;
l=length(seq);
k=2;
%statistic?the?symbol?that?in?the?source?file?and??the?numbers.
for?i=2:l
????%check?whether?there?is?the?current?symbol?in?the?alpha?array
????idx=find(alpha==seq(i));
????if?isempty(idx)%if?notadd?it
????????alpha(k)=seq(i);
????????prob(k)=1;
????????k=k+1;
????else
????????prob(idx)=prob(idx)+1;?%if?there?is?add?1
????end
end
%caculate?the?probability
prob=prob./l;
%caculate?the?entropy
entropy=-prob.*log2(prob);
entropy=sum(entropy(:));
end
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????4989??2009-12-11?10:21??LZ\decode.txt
?????文件??????17721??2009-12-11?10:21??LZ\encode.txt
?????文件????????602??2009-09-28?13:18??LZ\Entropy.m
?????文件????????826??2009-09-28?13:05??LZ\LZcode.m
?????文件????????251??2009-09-28?13:13??LZ\LZdecode.m
?????文件????????245??2009-09-28?13:12??LZ\LZencode.m
?????文件???????1370??2009-09-28?13:24??LZ\LZmain.m
?????文件???????4991??2009-09-24?00:18??LZ\source.txt
?????目錄??????????0??2009-12-11?10:19??LZ
-----------?---------??----------?-----??----
????????????????30995????????????????????9
評論
共有 條評論