Thread Subject: add/remove elements in mex sparse format

Subject: add/remove elements in mex sparse format

From: Jimmy Kovarians

Date: 24 Nov, 2009 18:17:22

Message: 1 of 4

Hello, I am currently working on a mex-file from where I am manipulating sparse matrices.

I have a sparse matrix, defining an adjency matrix, where all elements are the same.
So following the MATLAB help topics on handling sparse arrays I have managed to define the array by two vectors, ir and jc (as all elements are the same, pr is not important).

What I want to do now is to add and remove elements from this sparse matrix, but this seem to be quite cumbersome, or have I missed the point here? I cannot see a simple way of doing this without writing a new sparse matrix and declaring ir and jc again. Are there any trix to use here?

 Jimmy

Subject: add/remove elements in mex sparse format

From: Bruno Luong

Date: 24 Nov, 2009 18:41:19

Message: 2 of 4

"Jimmy Kovarians" <kovarians@gmail.com> wrote in message <heh7vi$el9$1@fred.mathworks.com>...

>
> What I want to do now is to add and remove elements from this sparse matrix, but this seem to be quite cumbersome, or have I missed the point here? I cannot see a simple way of doing this without writing a new sparse matrix and declaring ir and jc again. Are there any trix to use here?

No trick to use. Welcome to sparse mex programming.

Bruno

Subject: add/remove elements in mex sparse format

From: Jimmy Kovarians

Date: 24 Nov, 2009 18:48:05

Message: 3 of 4

Hehe, ok, thanks.

I just clear out the headache then..

 Jimmy

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <heh9cf$ccr$1@fred.mathworks.com>...
> "Jimmy Kovarians" <kovarians@gmail.com> wrote in message <heh7vi$el9$1@fred.mathworks.com>...
>
> >
> > What I want to do now is to add and remove elements from this sparse matrix, but this seem to be quite cumbersome, or have I missed the point here? I cannot see a simple way of doing this without writing a new sparse matrix and declaring ir and jc again. Are there any trix to use here?
>
> No trick to use. Welcome to sparse mex programming.
>
> Bruno

Subject: add/remove elements in mex sparse format

From: Jimmy Kovarians

Date: 24 Nov, 2009 19:38:00

Message: 4 of 4

Ok, I got an idea here. I add and remove elements in the sparse matrix by using indices as for example if ir has 6 non-zero elements and 3 is removed I write

ir(3:5)=ir(4:6)
ir(6)=0

But I start to think, will this idea be slower than vectorized code in MATLAB where I can update a whole column in the matrix by for example

A(:,6)=new_relation
  
I got a bit curious here, how does MATLAB handle the above if A is sparse?
Is a new A allocated?

 Jimmy

"Jimmy Kovarians" <kovarians@gmail.com> wrote in message <heh9p5$7bb$1@fred.mathworks.com>...
> Hehe, ok, thanks.
>
> I just clear out the headache then..
>
> Jimmy
>
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <heh9cf$ccr$1@fred.mathworks.com>...
> > "Jimmy Kovarians" <kovarians@gmail.com> wrote in message <heh7vi$el9$1@fred.mathworks.com>...
> >
> > >
> > > What I want to do now is to add and remove elements from this sparse matrix, but this seem to be quite cumbersome, or have I missed the point here? I cannot see a simple way of doing this without writing a new sparse matrix and declaring ir and jc again. Are there any trix to use here?
> >
> > No trick to use. Welcome to sparse mex programming.
> >
> > Bruno

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
mex Jimmy Kovarians 24 Nov, 2009 13:19:26
sparse Jimmy Kovarians 24 Nov, 2009 13:19:26
index Jimmy Kovarians 24 Nov, 2009 13:19:26
rssFeed for this Thread

Contact us at files@mathworks.com