mexCallMATLAB ... Help me please.
显示 更早的评论
Hi Everyone I am new in this. Let me ask you a dumb question about MEX routines.
I am trying to implement mexCallMATLAB(1, &B, 1, &A, "floor"); inside a routine, but I cannot figure out how to setup B and A as any number. I have tried everything but I have not had good results. This is the code. I need B as an input to other calculations at the end. But it seems that I am not getting anything from mexCallMATLAB.
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
mxArray *A, *B;
double *d;
d = (double*)mxMalloc(1 * sizeof( double ));
A = mxCreateNumericMatrix(0, 0, mxDOUBLE_CLASS, mxREAL);
d[0] = 3.123;
mxSetData(A, d);
mexCallMATLAB(1, &B, 1, &A, "floor");
plhs[0] = B;
..... More code....}
回答(1 个)
James Tursa
2012-6-8
mxArray *A;
double *d;
A = mxCreateNumericMatrix(1, 1, mxDOUBLE_CLASS, mxREAL);
d = mxGetPr(A);
d[0] = 3.123;
mexCallMATLAB(1, plhs, 1, &A, "floor");
类别
在 帮助中心 和 File 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!