title: Transform a matrix to a stacked vector where all zeroes after the last non-zero value per row are removed
body: <p>I have a matrix with some zero values I want to erase.</p>
  
  <pre><code>a=[ 1 2 3 0 0; 1 0 1 3 2; 0 1 2 5 0]
  
  &gt;&gt;a =
  
   1     2     3     0     0
   1     0     1     3     2
   0     1     2     5     0
  </code></pre>
  
  <p>However, I want to erase only the ones after the last non-zero value of each line.
  This means that I want to retain <code>1 2 3</code> from the first line, <code>1 0 1 3 2</code> from the second and <code>0 1 2 5</code> from the third.</p>
  
  <p>I want to then store the remaining values in a vector. In the case of the example this would result in the vector</p>
  
  <pre><code>b=[1 2 3 1 0 1 3 2 0 1 2 5]
  </code></pre>
  
  <p>The only way I figured out involves a <code>for</code> loop that I would like to avoid:</p>
  
  <pre><code>b=[];
  for ii=1:size(a,1)
      l=max(find(a(ii,:)));
      b=[b a(ii,1:l)];
  end
  </code></pre>
  
  <p>Is there a way to vectorize this code?</p>