This line is incorrect (wrong function and signature):
plhs[0] = mxCreateNumericArray(xynum,1,mxINT16_CLASS); /*Creates a matrix*/
It should be this instead:
plhs[0] = mxCreateNumericMatrix(xynum,1,mxINT16_CLASS,mxREAL); /*Creates a matrix*/
Also, these lines will not work:
int gnum, xynum, *gn;
:
gn = mxGetInt16s(plhs[0]); /*Set to be the first of the output values*/
An int on your system is almost surely a 32-bit integer, not a 16-bit integer. You need to make sure your pointer definition matches exactly what is in memory. E.g., you can probably use a short int for this:
int gnum, xynum;
short *gn;
:
gn = mxGetInt16s(plhs[0]); /*Set to be the first of the output values*/
That will mean you need to change this signature:
void findnegs(double *phi, int gnum, int xynum, int *gn, double *adj, double *newphi, double *dphidtSum)
to this instead also:
void findnegs(double *phi, int gnum, int xynum, short *gn, double *adj, double *newphi, double *dphidtSum)
But this begs the question, are integer calculations in the findnegs function now going to overflow your 16-bit integers in gn? You may need to adjust your code to make sure this isn't a problem.
Best Answer