Thread Subject: sparse matrix assembly without adding duplicate values

Subject: sparse matrix assembly without adding duplicate values

From: A B

Date: 20 Sep, 2009 10:04:02

Message: 1 of 2

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

Subject: sparse matrix assembly without adding duplicate values

From: John D'Errico

Date: 20 Sep, 2009 11:05:18

Message: 2 of 2

"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

Tags for this Thread

Everyone's Tags:

Add a New Tag:

Separated by commas
Ex.: root locus, bode

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Tag Activity for This Thread
Tag Applied By Date/Time
vector Sprinceana 20 Sep, 2009 07:01:26
3vectors Sprinceana 20 Sep, 2009 07:01:26
spase matrix Sprinceana 20 Sep, 2009 07:01:15
rssFeed for this Thread

Contact us at files@mathworks.com