title: Run Length Coding Matlab
body: <p>I am doing Run Length Coding in Matlab and so far I have implemented the zigzag algorithm and got an array RunLengthCoding: </p>
  
  <pre><code>RunLengthCoding = 
  (32, 6, -1, -1, 0, -1, 0, 0, 0, -1, 0, 0, 1, 0, 0,..., 0)
  </code></pre>
  
  <p>Now I need to run length code this such that I get: </p>
  
  <pre><code>(0,6) (0,-1) (0,-1) (1,-1) (3,-1) (2,1) (0,0)
  </code></pre>
  
  <p>This is (length,value), for example (0,6) because there is no 0 and we are at value 6, then when we meet the first 0 we get (1,-1) since there is one 0 and the value after it is -1.</p>
  
  <p>My attempt:</p>
  
  <pre><code>RunLengthCoding(1)=[]; %to remove first DC component
  relMat = [];
  N = 0;
  for i = 1:length(RunLengthCoding)-1
       if RunLengthCoding(i)==0;
            if RunLengthCoding(i)==RunLengthCoding(i+1)
                 N = N + 1;
            else
                valuecode = RunLengthCoding(i);
                lengthcode =  N;
                relMat = [relMat;  lengthcode valuecode];
                N = 1;
            end
          else
             relMat=[relMat; 0 RunLength(i)];  
      end
  </code></pre>
  
  <p>I know that this does not run! But that is what I have managed so far</p>