Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Matrix declaration in c-file for creating dll

Status
Not open for further replies.

marctangelder

Computer
Joined
May 13, 2002
Messages
1
Location
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);
}
 
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.

Part and Inventory Search

Sponsor

Back
Top