Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » Software » comp.soft-sys.matlab

Topic: How do I use a sparse matrix that was returned by a mex file?
Replies: 5   Last Post: Mar 10, 2013 10:39 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Tursa

Posts: 2,069
Registered: 8/5/09
Re: How do I use a sparse matrix that was returned by a mex file?
Posted: Mar 9, 2013 6:40 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

"Alejandro " <aortizb@ing.uchile.cl> wrote in message <khg44l$jq8$1@newscl01ah.mathworks.com>...
> "James Tursa" wrote in message <khfts1$3qb$1@newscl01ah.mathworks.com>...
> > "Alejandro " <aortizb@ing.uchile.cl> wrote in message <khfcj2$ij1$1@newscl01ah.mathworks.com>...
> > > Hi all,
> > >
> > > Say I created a sparse matrix (say K) in a mex file and returned to matlab environment. I read that sparse matrix has no information of the sparsity and cannot be used in any other matlab function that uses a sparse matrix.

> >
> > Wrong. If the sparse matrix was created correctly in the mex routine, you can use it just like any other sparse matrix that was created at the m-file level. You can use the FEX function spok to see if it was built properly:
> >
> > http://www.mathworks.com/matlabcentral/fileexchange/20186-spok-checks-if-a-matlab-sparse-matrix-is-ok
> >
> >
> > James Tursa

>
> Thanks James. I read somewhere in the manual what I mentioned above, so that cause me a doubt. Also, I haven't written the function yet. Maybe I misunderstood the manual, so I wanted to be sure I would be able to use the sparse matrix after it was created inside the mex function.
>
> What is not clear to me is the following. If only the sparse matrix that is created inside the mex function is returned to the matlab environment, how does matlab know the internal structure of that sparse matrix? do I have to return something else like ir and jc?


Inside the mex function you are required to fill in the pr, pi (if complex), ir, and jc arrays manually. If you do it correctly, the result will be a sparse matrix with the exact internal structure as if it was created at the m-file level.

James Tursa



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.