title: Matlab: assign to matrix with column\row index pairs
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/6850368/how-can-i-change-the-values-of-multiple-points-in-a-matrix">How can I change the values of multiple points in a matrix?</a>  </p>
  </blockquote>
  
  
  
  <p>I have a matrix <code>A</code> and three vectors of the same length, <code>r</code>, holding the indexes of the rows to assign to, <code>c</code>, holding the indexes of the columns to assign to, and <code>v</code> containing the actual values to assign. </p>
  
  <p>What I want to get is <code>A(r(i),c(i))==v(i)</code> for all <code>i</code>. But doing </p>
  
  <pre><code>A(r,c)=v;
  </code></pre>
  
  <p>Doesn't yield the correct result as matlab interprets it as choosing every possible combination of <code>r</code> and <code>c</code> and assigning values to it, for instance</p>
  
  <pre><code>n=5;
  A=zeros(n);
  r=1:n;
  c=1:n;
  
  A(r,c)=1;
  </code></pre>
  
  <p>Yields a matrix of ones, where I would like to get the identity matrix since I want <code>A(r(i),c(i))==1</code> for each <code>i</code>, that is only elements on the diagonal should be affected.</p>
  
  <p>How can I achieve the desired result, without a <code>for</code> loop?</p>