shetlandbob
Aerospace
- Jul 6, 2005
- 2
Hi folk!
Thanks for taking time to read this. I am trying to create a dll in Matlab 6.5.1.199709 (R13) Service Pack 1
I've reduced it down to a smaller example:
I'v searched the help/internet and cant see whats wrong with the code?
I compile and run with
The output should be a structured array with 3 variables, each containing 5 elements.
It runs ok the first time I try to run it (90%), but subsequent runs it crashes and I have to exit matlab to get it to work again?
Any input/help much appreciated.
Thanks
Thanks for taking time to read this. I am trying to create a dll in Matlab 6.5.1.199709 (R13) Service Pack 1
I've reduced it down to a smaller example:
Code:
#include "mex.h"
void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[] )
{
char** fnames;
char* pText;
char* buf;
char* pData;
char text[80][3];
int mrows,ncols,i,nfields,buflen;
mxArray* array;
size_t sizebuf;
double myData[10];
nfields = 3;
/* Check for proper number of arguments. */
if(nrhs!=1) { mexErrMsgTxt("One input required."); }
else if(nlhs>1) { mexErrMsgTxt("Too many output arguments"); }
/* The input must be a noncomplex scalar double.*/
mrows = mxGetM(prhs[0]);
ncols = mxGetN(prhs[0]);
if( !mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows==1 && ncols==1) ) { mexErrMsgTxt("Input must be a noncomplex scalar double."); }
// Build Field Array Names;
fnames = mxMalloc(nfields, sizeof(*fnames));
for ( i = 0; i < nfields; i++ )
{
sprintf ( text[i], "F%i", i+1 );
pText = text[i];
fnames[i] = pText;
printf ( "%i.%s\n", i+ 1, fnames[i] );
}
plhs[0] = mxCreateStructMatrix(1, 1, nfields, fnames);
printf ( "Created Dummy Structure\n" );
mxFree(fnames);
array = mxCreateDoubleMatrix(1,5, mxREAL);
for ( i = 0; i < 5; i++ ) myData[i] = i+0.1;
mxSetPr(array, myData);
mxSetM(array,1);
mxSetN(array,5);
mxSetFieldByNumber(plhs[0], 0, 0, array);
mxSetFieldByNumber(plhs[0], 0, 1, array);
mxSetFieldByNumber(plhs[0], 0, 2, array);
printf ( "done\n" );
}
I compile and run with
Code:
mex test.c
text(1.1)
It runs ok the first time I try to run it (90%), but subsequent runs it crashes and I have to exit matlab to get it to work again?
Any input/help much appreciated.
Thanks