Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

Matrix declaration in c-file for creating dll

Status
Not open for further replies.

marctangelder

Computer
May 13, 2002
1
0
0
NL
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);
}
 
Replies continue below

Recommended for you

Do you want a_ptr & b_ptr to be matrices? Use the command:
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.
 
Status
Not open for further replies.
Back
Top