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
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com