<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261224</link>
    <title>MATLAB Central Newsreader - sparse matrix assembly without adding duplicate values</title>
    <description>Feed for thread: sparse matrix assembly without adding duplicate values</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2012 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.com/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Sun, 20 Sep 2009 10:04:02 -0400</pubDate>
      <title>sparse matrix assembly without adding duplicate values</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261224#681351</link>
      <author>A B</author>
      <description>Hi&lt;br&gt;
&lt;br&gt;
I have three vectors&lt;br&gt;
&lt;br&gt;
i_row, j_col, s_val&lt;br&gt;
&lt;br&gt;
which I use for assemblying a sparse matrix.&lt;br&gt;
Usually the sparse command  adds any elements of s that have duplicate values of i and j together.  However I dont want to add up duplicate values. I just want to take the first occurence.&lt;br&gt;
&lt;br&gt;
Is there a simple way to way to remove duplicate entries. I tried to come up with something using &quot;unique&quot;, but it didnt work. Any other ideas...?&lt;br&gt;
&lt;br&gt;
Thanks</description>
    </item>
    <item>
      <pubDate>Sun, 20 Sep 2009 11:05:18 -0400</pubDate>
      <title>Re: sparse matrix assembly without adding duplicate values</title>
      <link>http://www.mathworks.com/matlabcentral/newsreader/view_thread/261224#681356</link>
      <author>John D'Errico</author>
      <description>&quot;A B&quot; &amp;lt;gitsnedbutzi@hotmail.com&amp;gt; wrote in message &amp;lt;h94umi$nrk$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; Hi&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; I have three vectors&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; i_row, j_col, s_val&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; which I use for assemblying a sparse matrix.&lt;br&gt;
&amp;gt; Usually the sparse command  adds any elements of s that have duplicate values of i and j together.  However I dont want to add up duplicate values. I just want to take the first occurence.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Is there a simple way to way to remove duplicate entries. I tried to come up with something using &quot;unique&quot;, but it didnt work. Any other ideas...?&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thanks&lt;br&gt;
&lt;br&gt;
That you tried unique and failed does not mean that&lt;br&gt;
unique is not the solution. It simply means that&lt;br&gt;
you used it incorrectly.&lt;br&gt;
&lt;br&gt;
This should do the trick, assuming column vectors:&lt;br&gt;
&lt;br&gt;
[u_ij,I] = unique([i_row,j_col],'rows','first');&lt;br&gt;
u_s_val = s_val(I);&lt;br&gt;
&lt;br&gt;
John</description>
    </item>
  </channel>
</rss>

