title: matlab: populating a sparse matrix with addition
body: <p><strong>preface:</strong> As the matlab guiderules state, Usually, when one wants to efficiently populate a sparse matrix in matlab, he should create a vector of indexes into the matrix and a vector of values he wants to assign, and then concentrate all the assignments into one atomic operation, so as to allow matlab to "prepare" the matrix in advance and optimize the assignment speed. A simple example:</p>
  
  <pre><code>A=sparse([]);
  inds=some_index_generating_method();
  vals=some_value_generating_method();
  A(inds)=vals;
  </code></pre>
  
  <p><strong>My question:</strong> what can I do in the case where <code>inds</code> contain overlapping indexes, i.e <code>inds=[4 17 8 17 9]</code> where 17 repeats twice.
  In this case, what I would want to happen is that the matrix would be assigned the addition of all the values that are mapped to the same index, i.e for the previous example </p>
  
  <pre><code>A(17)=vals(2)+vals(4) %as inds(2)==inds(4)
  </code></pre>
  
  <p>Is there any straightforward and, most importantly, <em>fast</em> way to achieve this? I have no way of generating the indexes and values in a "smarter" way.</p>