mxArray *A;
mwSize JDim = 4, IDim = 5;
double *squares;
A = mxCreateNumericArray(IDim, JDim, mxDOUBLE_CLASS, mxREAL);
squares = mxGetPr(A);
Now squares is a pointer to the data of the array. It can be filled using linear indexing:
i = 2; % 1-based indexing!
j = 3;
squares[i - 1 + (j - 1) * IDim] = 2; % 0-based indexing!
