Created
April 23, 2012 12:38
-
-
Save semihozkoroglu/2470673 to your computer and use it in GitHub Desktop.
Run-length sıkıstırma yöntemi
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function R = rle(Q) | |
len = length(Q); | |
son_eleman = len; | |
i = 1; eleman = 1; | |
R = {}; | |
tmp = str2mat('PXX'); | |
while len > 0 | |
if ~(i == son_eleman) | |
if Q(i) == Q(i+1) | |
eleman = eleman + 1; | |
else | |
if ~(eleman == 1) | |
if Q(i) < 0 | |
tmp(1) = 'N'; | |
Q(i) = -1*Q(i); | |
end | |
tmp(2) = num2str(eleman); | |
tmp(3) = num2str(Q(i)); | |
R{length(R)+1} = tmp; | |
eleman = 1; | |
else | |
R{length(R)+1} = Q(i); | |
end | |
end | |
else | |
if ~(eleman == 1) | |
if Q(i) < 0 | |
tmp(1) = 'N'; | |
Q(i) = -1*Q(i); | |
end | |
tmp(2) = num2str(eleman); | |
tmp(3) = num2str(Q(i)); | |
R{length(R)+1} = tmp; | |
eleman = 1; | |
else | |
R{length(R)+1} = Q(i); | |
end | |
end | |
i = i + 1; | |
len = len -1; | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment