title: Replace certain elements of matrix with NaN (MATLAB)
body: <p>I have a vector, A.</p>
  
  <pre><code>A=[3,4,5,2,2,4;2,3,4,5,3,4;2,4,3,2,3,1;1,2,3,2,3,4]
  </code></pre>
  
  <p>Some of the records in A must be replaced by NaN values, as they are inaccurate. 
  I have created vector rowid, which records the last value that must be kept after which the existing values must be swapped to NaN.</p>
  
  <pre><code>rowid=[4,5,4,3]
  </code></pre>
  
  <p>So the vector I wish to create, B, would look as follows:</p>
  
  <pre><code>B=[3,4,5,2,NaN,NaN;2,3,4,5,3,NaN;2,4,3,2,NaN,NaN;1,2,3,NaN,NaN,NaN]
  </code></pre>
  
  <p>I am at a loss as to how to do this. I have tried to use</p>
  
  <pre><code>A(:,rowid:end)
  </code></pre>
  
  <p>to start selecting out the data from vector A. I am expecting to be able to use sub2ind or some sort of idx to do this, possibly an if loop, but I don't know where to start and cannot find an appropriate similar question to base my thoughts on!</p>
  
  <p>I would very much appreciate any tips/pointers, many thanks</p>