필터 지우기
필터 지우기

needed help for mex with 3D output matrix

조회 수: 4 (최근 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 CenterFile Exchange에서 Write 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