MATLAB Answers

0

Is it possible to pass a sparse matrix to a MEX file (written for Fortran) as input?

Asked by Kai Drechsel on 18 May 2018 at 10:11
Latest activity Commented on by James Tursa
on 18 May 2018 at 16:33

I have two sparse matrices, both rather large, which should be used as the input for my mex file. It is no problem to do this with a full matrix but i want to avoid this due to the size of the matrices. Thanks for helping me.

  2 Comments

You can use sparse files directly as input to a mex function. There is e.g. the example code fulltosparse.c. So please explain, which problem you have. Maybe you want to convert the sparse format used by Matlab to a specific other format? Please mention the details.

Handling sparse matrices in C/C++ mex routines is tricky enough ... but in Fortran it is going to be even trickier due to the fact that it will be harder to work directly with the data pointers in Fortran. It can be done, but you will need to write Fortran code to convert the raw pointer values from the API routines (mxGetIr, mxGetJc, etc) to usable Fortran pointers first. What do you intend to do with these sparse matrices inside your mex function?

Sign in to comment.

Tags

0 Answers

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today