title: Replace some values of one MATLAB matrix with values from another
body: <p>I'm a new programmer, working in MATLAB, and I am hoping to substitute some values in one of my matrices with information from another matrix.</p>
  
  <p>So, for example, supposing I have one matrix [A]:  </p>
  
  <pre><code>A = [0  0  0  0  0  
      .5  0 .2 .8  0
       1 .3  1 .1 .1
       1  1 .4  1  1
       1  1  1  1  1] 
  </code></pre>
  
  <p>And another matrix B: </p>
  
  <pre><code>B = [.4 .3 .2 .1 .2] 
  </code></pre>
  
  <p>I would like to replace the first nonzero value in A with the one in the same column in matrix B such that: </p>
  
  <pre><code>A_new = [0  0  0  0  0  
          .4  0 .2 .1  0
           1 .3  1 .1 .2
           1  1 .4  1  1
           1  1  1  1  1] 
  </code></pre>
  
  <p>There are some values between 0 and 1 that I want to keep untouched which precludes just changing everything between 0 and 1 (exclusive). I'm sure the solution will involve an if statement and possibly a for loop, but I'm not sure how to set it up. Any advice is appreciated! </p>