Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to pass an array of double Image to mexFunction in matlab
    text
    copied!<p>I have already passed an image to my mexFunction but now I need to pass an array of images and I am struggling to get the thing right. This is my code to get the simple Image. This works perfectly but when I go into 3D I don't understand how the information is arranged in the mxArray.</p> <pre><code>void mexFunction(int nlhs, mxArray *plhs[], int nrhs, mxArray *prhs[]) { mxArray *matrixIn = prhs[0]; inputImage=(double *)mxGetPr(matrixIn); int x = int(dims[0]); int y = int(dims[1]); volume3D image(inputImage, x, y, 1); } volume3D::volume3D(double* image, int x, int y, int z) { allocateVolume( x, y, z); for(int i=0; i&lt;xSize; i++) for(int j=0; j&lt;ySize; j++) { volume[i][j][0] = double(image[(i)*x+j]); } } </code></pre> <p>I did something like this to pass it the other way around</p> <p>mwSize mrows,ncols; mrows = mxGetM(prhs[0]); ncols = mxGetN(prhs[0]);</p> <pre><code>plhs[0] = mxCreateNumericMatrix(mrows, ncols, mxDOUBLE_CLASS, mxREAL); double *matlabTumorMap = mxGetPr(plhs[0]); const int * dims = mxGetDimensions( plhs[0]); int x = int(dims[0]); int y = int(dims[1]); int z = int(dims[2]); mwIndex subs[3]; mexPrintf("x %i\n",x); mexPrintf("y %i\n",y); mexPrintf("z %i\n",z); mxArray *matrixTumor = plhs[0]; for(subs[0]=0; subs[0]&lt;x; subs[0]++) for(subs[1]=0; subs[1]&lt;y; subs[1]++) for(subs[2]=0; subs[2]&lt;z; subs[2]++) { mwIndex x = mxCalcSingleSubscript( matrixTumor,3,subs); matlabTumorMap[x] = tumorMap.getVoxel(subs[0],subs[1],subs[2]); } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload