Matrix declaration in c-file for creating dll
Matrix declaration in c-file for creating dll
(OP)
I want to make a dll for a VB program. The c-code below shows wrapper file with variables a and b. What code I have to build if I use matrixes instead of doubles?!?
#include "eigenwaardelib.h"
#include "matlab.h"
double __stdcall eigenwaardewrap(double a, double b)
{
mxArray *a_ptr;
mxArray *b_ptr;
mxArray *y_ptr;
double *y;
double ret;
/* Create an mxArray to input into mlfeigenwaarde */
a_ptr = mlfScalar(a);
b_ptr = mlfScalar(b);
eigenwaardelibInitialize();
y_ptr = mlfEigenwaarde(a_ptr, b_ptr);
/* The return value from mlfeigenwaarde is an mxArray so we must extract the data from it */
y = mxGetPr(y_ptr);
ret = *y;
/* Return a double precision number to Visual Basic */
return(ret);
}
#include "eigenwaardelib.h"
#include "matlab.h"
double __stdcall eigenwaardewrap(double a, double b)
{
mxArray *a_ptr;
mxArray *b_ptr;
mxArray *y_ptr;
double *y;
double ret;
/* Create an mxArray to input into mlfeigenwaarde */
a_ptr = mlfScalar(a);
b_ptr = mlfScalar(b);
eigenwaardelibInitialize();
y_ptr = mlfEigenwaarde(a_ptr, b_ptr);
/* The return value from mlfeigenwaarde is an mxArray so we must extract the data from it */
y = mxGetPr(y_ptr);
ret = *y;
/* Return a double precision number to Visual Basic */
return(ret);
}





RE: Matrix declaration in c-file for creating dll
a_ptr=mxCreateDoubleMatrix(nrows,ncols,MX_REAL);
Then you'll need to retreive a pointer to the mxArray to populate it with values (ap=mxGetPr(a_ptr)). The array is 1-D, so you can set index (2,3) to 1.1 with the command ap[(3-1)*nrows+2]=1.1
--Remember, MATLAB is columnwise, so it goes down the 1st column in the matrix, then the next, and so on.