I am trying to convert a 4D double matrix from Matlab to C++, using the below code however, it looks to me that mxGetPr() does not support linear mapping! are there any mapping indexing formula that can be used with this function (i.e ptr1[linear indexing formula] in the code below)?
MATFile *pmat;int dt1,dt2,dt3,dt4; dt1=3; dt2=4; dt3=5; dt4=6; % diemntions of the 4D matrix
vector<vector<vector<vector<double>>>> array4D1(dt1, vector<vector<vector<double>>> (dt2, vector<vector<double>> (dt3, vector<double> pa2 = matGetVariable(pmat, "G_wp"); % G_wp is a 3x4x5x6 matlab matrix (dt4))));
ptr1 = mxGetPr( pa2 ); int idx1=0;for (int i=0; i<dt1; i++ ) {for (int j=0; j<dt2; j++) {for (int k=0; k<dt3; k++) {for (int l=0; l<dt4; l++) {array4D1[i][j][k][l]=ptr1[idx1];idx1++;} } } }
Best Answer