needed help for mex with 3D output matrix

8 views (last 30 days)
Abeera Tariq
Abeera Tariq on 27 May 2015
Edited: James Tursa on 27 May 2015
It is the code for mex I am trying to generate.. it generates mex file successfully but matlab crashes out.. can someone spot the error?
#include "mex.h"
double IDWT(double x[10][64], double Dct_matrix[10][10], double IW[8][8], double out[10][8][8])
operations are performed on matrices
double out[10][8][8] is the output matrix
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
double **inMatrix;
double **inMatrix1;
double **inMatrix2;
double ***outMatrix;
inMatrix = mxGetPr(prhs[0]);
inMatrix1 = mxGetPr(prhs[1]);
inMatrix2 = mxGetPr(prhs[2]);
plhs[0] = mxCreateNumericArray(3,8,8,10,mxDOUBLE_CLASS,mxREAL);
outMatrix = mxGetPr(plhs[0]);

Accepted Answer

James Tursa
James Tursa on 27 May 2015
Edited: James Tursa on 27 May 2015
(1) You are calling mxCreateNumericArray improperly, and this is likely the cause of the crash. The signature from the doc is this:
mxArray *mxCreateNumericArray(mwSize ndim, const mwSize *dims,
mxClassID classid, mxComplexity ComplexFlag);
But you are passing in the dims individually. This is incorrect and doesn't match the signature above. You need to do this instead:
mwSize dims[3] = {8,8,10};
plhs[0] = mxCreateNumericArray(3,dims,mxDOUBLE_CLASS,mxREAL);
(2) Can you post what the exact variable sizes are in the calling routine (i.e., the m-file)? Since C is row based memory storage and MATLAB is column based memory storage, you would need to reverse your indexing in C to get at the MATLAB indexing. It looks like you might be accounting for that because your sizes in the mxCreateNumericArray call are reversed from your "out" variable dimensions in the IDWT signature, but I can't be sure until I see the calling routine variable sizes.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!