How to edit sparse matrix entries inside mex file?

3 views (last 30 days)
Hi all,
I have a large sparse matrix that I pass to a mex file I have written. At some stage in this mex file, I want to update some entries in this large sparse matrix. How do I access specific elements inside this sparse matrix and change them?
Thanks!
Siddharth
  7 Comments
James Tursa
James Tursa on 9 Jan 2016
Note that mexCallMATLAB always returns a deep copy ... it cannot be used for any in-place calculations. So if your intention is to write something that only changes a non-zero value to a different non-zero value quickly in-place, you definitely do not want to use mexCallMATLAB.
SiddharthKrishnamoorthy
SiddharthKrishnamoorthy on 11 Jan 2016
Yes, I found that out the hard way. Also the whole thing was really expensive (and wrong). I've now implemented a new way where I use the IR and JC matrices to arrive at the diagonals and edit the entry in the corresponding pr matrix.

Sign in to comment.

Answers (1)

Steven Lord
Steven Lord on 8 Jan 2016
You will need to manipulate the ir, pr (and pi if the data is complex), and jc. See this documentation page and this other documentation page for a description of the jc and ir pointers and the fulltosparse example on this third documentation page for an example of a similar type of manipulation.
You're also going to want to be very careful that your modifications don't result in an invalid sparse matrix.
  1 Comment
SiddharthKrishnamoorthy
SiddharthKrishnamoorthy on 8 Jan 2016
Thank you, I will look into this. I'm fairly certain that my modifications don't alter the structure of the sparse matrix, only the non-zero entries.

Sign in to comment.

Categories

Find more on Operating on Diagonal Matrices in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!