To be a little bit more specific - I only want to edit the diagonal terms - so a method that doesn't involve looping through all the entries would be better...
How to edit sparse matrix entries inside mex file?
3 views (last 30 days)
Show older comments
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
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.
Answers (1)
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.
See Also
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!