I am working with 2D arrays defined with double pointers, e.g,
double** array;
array = (double**) calloc(numRows, sizeof(double*));
for (int i = 0; i < numRows; i++)
{
array[i] = (double*) calloc(numCols, sizeof(double));
/* then array[i][j] = values */
}
// code to return matlab array
plhs[0] = mxCreateDoubleMatrix(numRows, numCols, mxREAL);
// memory copy
// ?????????
for (i = 0; i < numRows; i++){
free(array[i]);
}
free(array);
I want to return array
in matlab. An execution I have until now for the // memory copy
part and I think it is fine, please correct me is:
stacked1D = mxGetPr(plhs[0]);
int n = 0;
for ( int r = 0; r < max_degree; r++ )
for ( int c = 0; c < n_vars; c++ )
stacked1D[n++] = stacked2D[r][c];
I am wondered if we can do it with a mem-copy
function like this mxSetPr(OUT, *stacked2D);
which is not working in this syntax.
Could you please give a hint-explanation or possible answer?