How do I pass a two-dimensional matrix to a shared library created using MATLAB Compiler?

1 view (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
Use the mxCreateDoubleMatrix to create an empty matrix of the size you prefer and then populate the matrix.
Note that MATLAB is column major whereas 'C' is row major. Thus, you must make appropriate changes in your code.
For example, if you want to pass the following matrix to MATLAB generated shared library:
[1 2 3
4 5 6]
you will have to create the data using a C code similar to the one shown below:
double data[] = {1,2,3,4,5,6};
mxArray *input;
/* Create a 3X2 matrix instead of 2X3 matrix*/
input = mxCreateDoubleMatrix(3,2,mxREAL);
/* populate it with the required data */
memcpy( mxGetPr(input),data, sizeof(double)*6);
/* Transpose it before passing to the library */
input = mlfTranspose(input);

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!