No BSD License  

1.0

1.0 | 1 rating Rate this file 19 Downloads (last 30 days) File Size: 1.09 KB File ID: #19559

RUN LENGTH ENCODING

by

 

12 Apr 2008 (Updated )

rle is performed on a binay stream of data

| Watch this File

File Information
Description

rle is performed on a binary stream of data,
where in the 1st element is copied (same) as the binary data,
the next element is the no of times the first element,
the next element is the no of times the next binary logic data and so on
eg a=[0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1]
rle =[0<<1stbinary bit> 1<<no of 0's> 2<<no of 1's> 1<<no of 0's> 1<<no of 1's> 1 5 7 2 1 1]

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (2)
14 Apr 2008 fex observer

If this well-known reviewer tells the truth, you should remove this submission.

14 Apr 2008 Duane Hanselman

Not a function. Not vectorized in any way. Here is what the submission contains:
%
%{
RUN LENGTH ENCODING
rle is performed on a binay stream of data
where in the 1st element is copied (same) as the binay data,
the next element is the no of times the first element,
the next element is the no of times the next binary logic data and so on
eg a=[0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1]
rle =[0<<1stbinary bit> 1<<no of 0's> 2<<no of 1's> 1<<no of 0's> 1<<no of 1's> 1 5 7 2 1 1]
%}

a=input('enter any binay stream: ');
% works any format viz... double as well as logical format
% eg: [0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1];
% eg: logical([0 1 1 0 1 0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 1]);
n=2;

% this loop calculates the length <n> of run length encoding matrix on the
% input stream of binary data
% by checking no of times the logic level changes
for k=1:length(a)-1
if a(k)~=a(k+1)
n=n+1;
end
end

rle=ones(1,n); % Preallocate array +using memory efficiently
rle(1)=a(1);
m=2;
for i=1:k
if a(i)==a(i+1)
rle(m)= rle(m)+1;
else m=m+1;
end
end
display(rle); %is of type double
% the code is self explanatory

Contact us