《LZW编码算法matlab实现》由会员分享,可在线阅读,更多相关《LZW编码算法matlab实现(4页珍藏版)》请在金锄头文库上搜索。
1、-.LZW 编码算法,尝试使用matlab 计算%encoder LZW for matlab%yu 20170503clc;clear;close all;%初始字典dic = cell(512,1);for i = 1:256dici = num2str(i);end%输入字符串 a,按空格拆分成 A,注意加 1 对应围 1256a = input(input:,s);a = deblank(a);A = regexp(a,s+,split);L = length(A);for j=1:LAj = num2str(str2num(Aj)+1);endA_t = A1;%可识别序列B_t =
2、 test;%待验证词条d = 256;%字典指针b = 1;%输出指针B = cell(L,1);%输出初始output = ;%输出初始j=1;for j = 2:Lm=1;B_t =deblank(A_t, ,Aj);%合成待验证词条while(m = d)if strcmp(dicm,B_t)A_t = B_t;breakelsem=m+1;endendwhile(m = d+1)d = d+1;-.word.zl-.dicd = B_t;q=1;for q=1:dif strcmp(dicq,A_t)Bb = num2str(q);b = b+1;endendA_t = Aj;end
3、endfor q=1:d%处理最后一个序列输出if strcmp(dicq,A_t)Bb = num2str(q);b = b+1;endendfor n = 1:(b-1)Bn =num2str(str2num(Bn)-1);output=deblank(output, ,Bn);endoutput运算结果计算结果为 39 39 126 126 256 258 260 259 257 126LZW 解码算法,使用 matlab 计算%decoder LZW for matlab%yu 20170503-.word.zl.-.clc;clear;close all;%初始字典dic = cel
4、l(512,1);for i = 1:256dici = num2str(i);end%输入字符串 a,按空格拆分成 A,注意加 1 对应围 1256a = input(input:,s);a = deblank(a);A = regexp(a,s+,split);L = length(A);for j=1:LAj = num2str(str2num(Aj)+1);endB_t = A1;%待验证词条d = 256;%字典指针b = 1;%输出指针B = cell(L,1);%输出初始output = ;%输出初始j=1;Bb = char(dicstr2num(Aj);b = b+1;for
5、 j = 2:LBB = char(dicstr2num(Aj);B_d = regexp(BB,s+,split);%按空格拆分L_B = length(B_d);p=1;for p=1:L_BB(b+p-1) = B_dp;m=1;B_t =deblank(char(B_t), ,char(B_dp);%合成待验证词条while(m = d)if strcmp(dicm,B_t)B_t = B_t;breakelsem=m+1;end-.word.zl-.endwhile(m = d+1)d = d+1;dicd = B_t;B_t = B_dp;endendb = b+L_B;endfor n = 1:(b-L_B)Bn = num2str(str2num(Bn)-1);output=deblank(output, ,Bn);endoutput运算结果运算结果为 39 39 126 126 39 39 126 126 39 39 126 126 39 39 126 126-.word.zl