MATLAB - Get rid of leading zeros in each row of matrix, 1 at a time?
<p>I want to get rid of leading zeros in each row of a matrix, but limit it to eliminating one zero at a time.</p>

<p>This is my current solution, but is there a simpler way of doing it?</p>

<pre><code>a = [ 0 0 0 0 0 0 0 0 0 0
      0 0 5 2 3 4 0 0 0 0
      0 0 0 1 2 3 4 0 0 0
      0 0 1 2 3 0 0 0 0 0
      0 0 0 0 1 0 0 0 0 0
      1 0 0 0 0 0 0 0 0 0 ]

  b=zeros(size(a));
  for j=1:size(a,2)
  for i=1:size(a,1)
      temp=find(a(i,:),1,'first');
      candelete=min(2,temp);
      b(i,1:end-candelete+1)=a(i,candelete:end);
  end
  a=b
  end
</code></pre>

<p>EDIT:
I'm want to print every iteration, so that the first output will only have the first leading zero removed:</p>

<pre><code> 0     0     0     0     0     0     0     0     0     0
 0     5     2     3     4     0     0     0     0     0
 0     0     1     2     3     4     0     0     0     0
 0     1     2     3     0     0     0     0     0     0
 0     0     0     1     0     0     0     0     0     0
 1     0     0     0     0     0     0     0     0     0
</code></pre>

<p>the second will have 2 zeros removed, and so on...</p>