needed help for mex with 3D output matrix

3 ビュー (過去 30 日間)
Abeera Tariq
Abeera Tariq 2015 年 5 月 27 日
編集済み: James Tursa 2015 年 5 月 27 日
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]);
IDWT(inMatrix,inMatrix1,inMatrix2,outMatrix);
}

採用された回答

James Tursa
James Tursa 2015 年 5 月 27 日
編集済み: James Tursa 2015 年 5 月 27 日
(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.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeWrite C Functions Callable from MATLAB (MEX Files) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by