entropy.m

来自「利用MATLAB实现哈弗曼编码。 利用MATLAB实现哈弗曼编码。」· M 代码 · 共 11 行

M
11
字号
function h=entropy(p)
%H=ENTROPY(P)返回概率矢
%量P的熵函数。
if length (find (p<0))~=0
    error('Not a prob.vector,negative component(s)')
end
if abs (sum(p)-1)>10e-10,
    error ('Not a prob.vector,components do not add up to 1')
end
h=sum (-p.*log2(p));

⌨️ 快捷键说明

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