1.0

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

RUN LENGTH ENCODING

by Shoeb Temrikar

 

12 Apr 2008 (Updated 14 Apr 2008)

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  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (2)
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

14 Apr 2008 fex observer

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

Please login to add a comment or rating.
Tag Activity for this File
Tag Applied By Date/Time
coding theory Shoeb Temrikar 22 Oct 2008 09:57:31
information theory Shoeb Temrikar 22 Oct 2008 09:57:31
encoding Shoeb Temrikar 22 Oct 2008 09:57:31
rle Shoeb Temrikar 22 Oct 2008 09:57:31
binary stream Shoeb Temrikar 22 Oct 2008 09:57:31
length Shoeb Temrikar 22 Oct 2008 09:57:31
run length Shoeb Temrikar 22 Oct 2008 09:57:31
element Shoeb Temrikar 22 Oct 2008 09:57:31
encoding Graziella Valença 11 Nov 2008 16:13:18
run length vinoth kumar 27 Sep 2011 08:28:32

Contact us at files@mathworks.com