I'm writing a c++ code that opens Matlab API engine. In the demo file Matlab_ROOT/extern/examples/eng_mat/engdemo.cpp, it shows how to copy a simple 1d c style array to a mxArray:
mxArray *T = NULL; double time[10] = {};
T = mxCreateDoubleMatrix( 1,10,mxREAL);
memcpy((void*)mxGetPr(T), (void*)time, sizeof(time));
I can understand this code; so a 1d mxArray object stores the elements linearly.
However, suppose I have a 2d (or more) c array and mxArray of same size:
double time[3][5];
mxArray *T;
T = mxCreateDoubleMatrix(3,5,mxREAL);
and I want to copy the elements of the c array time into mxArray T. How can I do this? I suppose if I use memcpy, it would depend on the sequence of element storage in mxArray objects. Thanks!