现在的位置: 首页 > 综合 > 正文

MATLAB中mexFunction函数的注意事项

2013年10月10日 ⁄ 综合 ⁄ 共 892字 ⁄ 字号 评论关闭

void mexFunction( int nlhs, mxArray *plhs[], int nrhs, const mxArray*prhs[] )
{  
 double *Fig , Fig_Handle;
 char Command[Command_LEN],Value[4];
 char *stats;//这些变量只能在所有语句之前声明,不能在中间声明

 if (nrhs != 3)
  mexErrMsgTxt("Three input arguments required.");

double Handle;  //这样做,是错误的,因为在语句之后声明
 ///////////////////////////////////////////////

 if(!mxIsDouble(prhs[0])) return;

 Fig=mxGetPr(prhs[0]);
 Fig_Handle=Fig[0];
 if (mxIsChar(prhs[1]) && mxIsChar(prhs[2]))
 {
  mxGetString(prhs[1], Command, Command_LEN);
  mxGetString(prhs[2], Value, 4);
  strlwr(Command);
  strlwr(Value);
  if (strncmp(Command, "topmost", 7) == 0)
  {
   if(strncmp(Value, "on", 2) == 0)
    stats=TopMostMe(Fig_Handle,1);//printf("Command=%s\n",Command)
   else
    stats=TopMostMe(Fig_Handle,0);
  }
  else if(strncmp(Command, "hook", 4) == 0)
  {
   if(strncmp(Value, "on", 2) == 0)
    stats=SetHookKeyboard();
   else
    stats=UnHookKeyboard();
  }

  plhs[0]=mxCreateString(stats);
 }
 


 return;
}

抱歉!评论已关闭.