title: Run Length Encoding in Matlab
body: <p>I'm very new with MatLab, I have Run Length Encoding code but it seems to not work, can you help me? </p>
  
  <p>I have this input : </p>
  
  <pre><code>ChainCode  = 11012321170701000700000700766666666666665555555544443344444333221322222322 
  </code></pre>
  
  <p>and I want make it into RLE output : </p>
  
  <pre><code>(1,2), (0,1), (1,1), (2,1), (3,1), (2,1), (1,2), (7,1), (0,1), (7,1), (0,1), 
  (1,1), (0,3), (7,1), (0,5), (7,1), (0,2), (7,1), (6,13), (5,8), (4,4), (3,2), 
  (4,5), (3,3), (2,2), (1,1), (3,1), (2,5), (3,1), (2,2) 
  </code></pre>
  
  <p>This is my code :</p>
  
  <pre><code>lengthcode = 1;
  N = 1;
  
  for i = 2:length(ChainCode)
  
      if x(i)==x(i-1)
          N = N + 1; 
          valuecode(N)  = x(i);
          lengthcode(N) = lengthcode(N) + 1;
      else 
          N = 1;
          lengthcode = 1;
      end
  
      i = i + 1;
  
  end
  </code></pre>
  
  <p>But this is not working, and I am still confused about how can I print the output like that. </p>
  
  <p>I hope you can help me. Thank you. </p>