MATLAB爱好者论坛-LabFans.com

MATLAB爱好者论坛-LabFans.com (https://www.labfans.com/bbs/index.php)
-   MATLAB论坛 (https://www.labfans.com/bbs/forumdisplay.php?f=6)
-   -   【求助】算术编码的matlab实现 (https://www.labfans.com/bbs/showthread.php?t=1918)

yinxuewang 2008-03-28 14:16

【求助】算术编码的matlab实现
 
【求助】算术编码的matlab实现
我现在已经找到一个简单的程序
但还满足不了要求
希望大侠赐教
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% 算术编码过程实例ssbm.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
about={...
'本实例说明:'
'字符串不能太长,程序不加判断,请注意溢出;'
'本实例只限定少数字符串 a b c d e;'
'实例只是说明一下算术编码过程。'};
disp(about);
str=input('请输入编码的字符串(本程序仅仅是一个实例,请仅输入a b c d e):');
l=0;r=1;d=1;
%初始间隔
%程序限定字符为:a、b、c、d、e
p=[0.2 0.3 0.1 0.15 0.25];
%字符的概率分布,sum(p)=1
n=length(str);
disp('a b c d e')
disp(num2str(p))
for i=1:n
switch str(i)
case 'a'
m=1;
case 'b'
m=2;
case 'c'
m=3;
case 'd'
m=4;
case 'e'
m=5;
otherwise
error('请不要输入其它字符!');
end
%判断字符
pl=0;pr=0;
for j=1:m-1
pl=pl+p(j);
end
for j=1:m
pr=pr+p(j);
end
%概率统计
l=l+d*pl;
r=l+d*(pr-pl);
strl=strcat('输入第',int2str(i),'符号的间隔左右边界:');
disp(strl);
format long
disp(l);disp(r);
d=r-l;
end


所有时间均为北京时间。现在的时间是 11:10

Powered by vBulletin
版权所有 ©2000 - 2025,Jelsoft Enterprises Ltd.