Path: news.mathworks.com!not-for-mail
From: "John D'Errico" <woodchips@rochester.rr.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: sparse matrix assembly without adding duplicate values
Date: Sun, 20 Sep 2009 11:05:18 +0000 (UTC)
Organization: John D'Errico (1-3LEW5R)
Lines: 24
Message-ID: <h9529e$1mj$1@fred.mathworks.com>
References: <h94umi$nrk$1@fred.mathworks.com>
Reply-To: "John D'Errico" <woodchips@rochester.rr.com>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1253444718 1747 172.30.248.37 (20 Sep 2009 11:05:18 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 20 Sep 2009 11:05:18 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 869215
Xref: news.mathworks.com comp.soft-sys.matlab:571607


"A B" <gitsnedbutzi@hotmail.com> wrote in message <h94umi$nrk$1@fred.mathworks.com>...
> Hi
> 
> I have three vectors
> 
> i_row, j_col, s_val
> 
> which I use for assemblying a sparse matrix.
> 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.
> 
> Is there a simple way to way to remove duplicate entries. I tried to come up with something using "unique", but it didnt work. Any other ideas...?
> 
> Thanks

That you tried unique and failed does not mean that
unique is not the solution. It simply means that
you used it incorrectly.

This should do the trick, assuming column vectors:

[u_ij,I] = unique([i_row,j_col],'rows','first');
u_s_val = s_val(I);

John