我的LZW码压缩最后一位出不来,请帮忙看看这个程序哪里不对头啊??
我的LZW码压缩最后一位出不来,请帮忙看看这个程序哪里不对头啊??function COMPRESS(str, str_single, string)
stringlen = length(string);
strlen = length(str);
strsinglelen = length(str_single);
[N, M] = size(str);
k = 0;
result(1) = 0;
js = 0;
for i = strsinglelen + 1 : strlen
k = k + 1;
F = 0;
for n = 1 : i-1
P = 0;
for j = 1 : M
if str(i, j) ~= 0
if str(i, j) == str(n, j)
F = F + 1;
P = n;
result(k) = n;
if F == 1
strlen = result;
end;
end;
if str(i,j) ~= str(n,j)
if P == n
if F == 2
F = F - 1;
result = strlen;
end;
end;
if i == strlen
js = 1;
end;
break;
end;
end;
end;
end;
end;
if js == 1
a = string(stringlen);
for i = 1 : strsinglelen+1
if a == str(i)
result(k + 1) = i;
break;
end;
end;
end;
result = result
DECOMPRESS(str, result);
我改过几种情况了,可是都出不来正确的,到底该怎样改才能达到好的压缩效果呢?