Skip to content

Instantly share code, notes, and snippets.

@semihozkoroglu
Created April 23, 2012 12:38
Show Gist options
  • Save semihozkoroglu/2470673 to your computer and use it in GitHub Desktop.
Save semihozkoroglu/2470673 to your computer and use it in GitHub Desktop.
Run-length sıkıstırma yöntemi
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