【发布时间】:2014-04-09 18:48:13
【问题描述】:
这是我的代码的一部分:
double h;
double sigma;
/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double *nor;
int n = mxGetScalar(prhs[0]);
h = mxGetScalar(prhs[1]);
nor = mxGetPr(prhs[2]);
sigma = mxGetScalar(prhs[3]);
double *x;
/* create the output vector */
plhs[0] = mxCreateDoubleMatrix(1,n,mxREAL);
/* get a pointer to the real data in the output matrix*/
x = mxGetPr(plhs[0]);
/* call the computational routine */
createTRR(x,n,nor);
}
如果我尝试在 matlab 中使用 mex myfilename.c 编译它,我会收到以下错误:
- 错误 C2143:语法错误:缺少 ';'在“类型”之前(在这一行中:
double *x;) - error C2065: 'x' : undeclared identifier (in this line
x = mxGetPr(plhs[0]);) 和 - error C2065: 'x' : undeclared identifier (in this line
createTRR(x,n,nor);)
我看不出有什么问题,我也不明白为什么没有为 *nor 抛出错误而只为 *x 抛出错误。我在 ubuntu 上用 Matlab2012 编写了代码,它工作正常。现在,我目前在 Win7 上使用 Matlab 2013b 和 Microsoft 软件开发工具包 (SDK) 7.1 作为 C++ 编译器。
【问题讨论】:
-
h、nor和sigma声明在哪里? -
@JohnnyMopp h 和 sigma 被声明为全局,请参阅编辑后的代码。也没有在 mexFunction 的第一行定义。