在c ++ matlab代码奇怪的错误 [英] Strange error on c++ matlab code

查看:105
本文介绍了在c ++ matlab代码奇怪的错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码的一部分:

  double h; 
double sigma;

/ *网关函数* /
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;

/ *创建输出向量* /
plhs [0] = mxCreateDoubleMatrix(1,n,mxREAL);

/ *获取指向输出矩阵中实际数据的指针* /
x = mxGetPr(plhs [0]);

/ *调用计算程序* /
createTRR(x,n,nor);
}



如果我试图在matlab中编译mex myfilename.c我得到以下错误:


  1. 错误C2143:语法错误:缺少';'before'type'(在此行中: double * x;

  2. 错误C2065:'x':undeclared标识符(在此行 x = mxGetPr(plhs [0] ); c>)

  3. 错误C2065:'x':undeclared标识符(在此行 createTRR ,nor);

我看不出有什么问题,我也不明白为什么没有错误抛出为*也不,但只为* x。我写的代码与Matlab2012在Ubuntu和它的工作。现在我正在使用Matlab 2013b在Win7与Microsoft软件开发工具包(SDK)7.1作为C ++编译器。

解决方案

您的代码是C ++,而不是严格c:您声明变量 x 开始代码的函数。你可能还记得在C中你必须在函数的代码之前声明所有的局部变量。



Cahnge你的文件扩展名为cpp和re-mex它。

This is part of my code:

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);
}

If I try to compile it in matlab with mex myfilename.c I get the following errors:

  1. error C2143: syntax error : missing ';' before 'type' (in this line: double *x; )
  2. error C2065: 'x' : undeclared identifier (in this line x = mxGetPr(plhs[0]);) and
  3. error C2065: 'x' : undeclared identifier (in this line createTRR(x,n,nor);)

I dont see whats wrong, and I also dont understand why no error is thrown for *nor but only for *x. I wrote the code with Matlab2012 on ubuntu and it worked. Now I am currently using Matlab 2013b on Win7 with Microsoft Software Development Kit (SDK) 7.1 as C++ compiler.

解决方案

your code is C++ and not strictly c: you declare variable x after the begining of the code of the function. As you may recall in C you must declare all local variables before the code of the function.

Cahnge your file extension to cpp and re-mex it.

这篇关于在c ++ matlab代码奇怪的错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆