title: Matlab or R: replace elements in matrix by values from another matrix in order
body: <p>I have a problem to solve in either Matlab or R (preferably in R).</p>
  
  <p>Imagine I have a vector A with 10 elements. </p>
  
  <p>I have also a vector B with 30 elements, of which 10 have value 'x'.</p>
  
  <p>Now, I want to replace all the 'x' in B by the corresponding values taken from A, <em>in the order that is established in A</em>. Once a value in A is taken, the next one is ready to be used when the next 'x' in B is found.</p>
  
  <p>Note that the sizes of A and B are different, it's the number of 'x' cells that coincides with the size of A.</p>
  
  <p>I have tried different ways to do it. Any suggestion on how to program this?</p>