How to edit sparse matrix entries inside mex file?
이전 댓글 표시
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
SiddharthKrishnamoorthy
2016년 1월 8일
James Tursa
2016년 1월 8일
Manipulating sparse matrices in a mex routine can be very tricky. Are the diagonal elements currently non-zero? Are you changing any non-zero elements to zero or vice-versa? If so, you will need to rewrite the entire matrix into a new area of memory (i.e., changes can't be done in-place). Let us know what exactly you are doing and then I can supply some example mex code to do it if it can be done in-place. If it can't be done in-place then the code will be much more involved.
SiddharthKrishnamoorthy
2016년 1월 8일
James Tursa
2016년 1월 8일
OK. I will work up a short example and post it later on.
SiddharthKrishnamoorthy
2016년 1월 8일
James Tursa
2016년 1월 9일
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
2016년 1월 11일
답변 (1개)
Steven Lord
2016년 1월 8일
1 개 추천
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.
카테고리
도움말 센터 및 File Exchange에서 Write C Functions Callable from MATLAB (MEX Files)에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!