title: Replace zeros with following nonzero value in MATLAB
body: <p>I have a vector <code>A</code>, which contains values that are <code>zeros</code>. I would now like to replace all <code>zeros</code> with the following non-zero value. I found this <a href="https://stackoverflow.com/questions/34041614/replace-all-zeros-in-vector-by-previous-non-zero-value">solution by @Luis Mendo</a> to replace zeros with the previous non-zero values.</p>
  
  <pre><code>A = [1 0 2 0 7 7 7 0 5 0 0 0 9];
  t = cumsum(A~=0);
  u = nonzeros(A);
  B = u(t).';
  </code></pre>
  
  <p>Is there a similar way to replace the <code>zeros</code> with the closest following non-zero value as well?</p>