Can someone help me to implement this algorithm I have tried to but get errors

Algorithm
Last code = 255
Series = First input character
While not end of while
character = next input character
if (series + character in code table)
series = series + character
else
output = code for series
add series and character to code table
series = character
end
end
output = code for series
Here is my code:
a=[39 39 126 126;39 39 126 126;39 39 126 126;39 39 126 126];
[f,g]=size(a);
total = f*g;
count=1;
imgchar= a(:)';
lastcode = 255;
tel = 1;
reeks = imgchar(1,1);
reekstr = num2str(reeks);
for j = 2:total
kodetabel{j}= strcat(' ');
reekskar{j}= strcat(',');
end
for i=2:total
karakter(1,i)=imgchar(1,i);
karstr = num2str(karakter(1,i));
reekskar{i} = strcat([reekstr,' ',karstr]);
waar = 0;
for k=2:total
if reekskar{i}==kodetabel{k}
reeks= reekskar{i};
waar=1;
end
end
if waar==0
output{tel}=reekstr;
kodetabel{i}=reekskar{i};
lastcode = lastcode+1;
kodetabelnr{i}=lastcode;
reeks=karakter(1,i);
tel = tel+1;
end;
end;
output{tel}=reeks;

2 件のコメント

Laurent
Laurent 2013 年 10 月 7 日
What is the error you get and in which line does it happen?
Martin Park
Martin Park 2013 年 10 月 7 日
Error using == Matrix dimensions must agree.
Error in lzw (line 29) if reekskar{i}==kodetabel{k}

回答 (2 件)

Laurent
Laurent 2013 年 10 月 7 日
It depends a bit on what result you want, but if you change that line to
if strcmp(reekskar{i},kodetabel{k})
the script runs. I don't know if this what you want, but at least there is a result. If you want something else, please tell us the result that you expect.

3 件のコメント

There is error in my code can you maybe help: When doing the algorithm by hand this is what I must get:
a series character code tabel output
39 39
39 39 39 256=29,39 39
126 39 126 257=39,126 39
126 126 126 258=126,126 126
39 126 39 259=126,39 126
39 39 39
126 39,39 126 260=39,39,126 256
126 126 126
39 126,126 39 261=126,126,39 258
39 39 39
126 39,39 126
126 39,39,126 126 262=39,39,126,126 260
39 126 39
39 126,39 39 263=126,39,39 259
126 39 126
126 39,126 126 264=39,126,126 257
126 126
Help with this would be much appreciated
Martin Park
Martin Park 2013 年 10 月 7 日
series in my code is named reeks and character is named karakter and code table is kode tabel
Martin Park
Martin Park 2013 年 10 月 7 日
when following the algorithm above i get the output
Martin Park
Martin Park 2013 年 10 月 7 日

0 投票

Can anyone help me please

この質問は閉じられています。

タグ

質問済み:

2013 年 10 月 7 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by