MATLAB: Incompatible type with mxCreateNumericArray

incompatible typesmexfunctionmxcreatenumericarray

Hi, I'm trying to create a mexfunction but I have some problems with compilation… I wrote this piece of code:
//global variables int Y_dimx,Y_dimy,Y_dimz,nS; double *Y;
mexfunction() {
mxArray* dim = mxGetField(prhs[0],0,"dim");
double* Y_dim=(double*) mxGetData(dim);
Y_dimx = Y_dim[0];
Y_dimy = Y_dim[1];
Y_dimz = Y_dim[2];
nS = 72;
const int outDims[4] = {nS,Y_dimx,Y_dimy,Y_dimz};
plhs[0] = mxCreateNumericArray(4,outDims,mxDOUBLE_CLASS,mxREAL); (*)
Y = (double*)mxGetData(plhs[0]);
At line (*) I get the following compilation error: argument of type "const int *" is incompatible with parameter of type "const size_t * '
I can't understand the reason for this error… Can you help me? Thank you very much.. Davide

Best Answer

It is complaining because you declared outDims as an int array (which when used as an argument gets converted to const int *), but the function expected something else (const size_t *). Use an mwSize for this to be generic. Try this:
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
{
:
const mwSize outDims[4] = {nS,Y_dimx,Y_dimy,Y_dimz};