⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mexeval.c

📁 matlab下面仿真802.3协议以太网mac层10、100M的网络接口模型。包括pci接口。
💻 C
字号:
#include "mex.h"

/*
 * mexeval.c : Example MEX-file code emulating the functionality of the
 *             MATLAB command EVAL
 *
 *              
 * Copyright 1984-2000 The MathWorks, Inc.
 * $Revision: 1.6 $
 */

void
mexFunction( int nlhs, mxArray *plhs[],
	     int nrhs, const mxArray *prhs[] )
{
  if(nrhs==0)
    mexErrMsgTxt("Function 'mexeval' not defined for variables of class 'double'.\n");

  else if(!mxIsChar(prhs[0])) {
    const char str[]="Function 'mexeval' not defined for variables of class";
    char errMsg[100];
    
    sprintf(errMsg,"%s '%s'\n",str,mxGetClassName(prhs[0]));
    mexErrMsgTxt(errMsg);
  }
  
  else {
    /* causes MATLAB to execute the string as an expression 
     * or statement the biggest limitation is that it won't 
     * evaluate any left-hand arguments except 'ans'
     */
    char *fcn;
    int   status;
    int   buflen=mxGetN(prhs[0])+1;
    
    fcn=(char *)mxCalloc(buflen,sizeof(char));
    status=mxGetString(prhs[0],fcn,buflen);
    
    status=mexEvalString(fcn);
    
    if((nrhs==2)&&(status)) {
      /* provides the ability to catch errors.  It
       * executes string s1 and returns if the operation was
       * successful. If the operation generates an error,
       * string s2 is evaluated before returning.
       */
      char *cmd;
      int   buflen;
      
      buflen=mxGetN(prhs[1])+1;
      cmd=(char *)mxCalloc(buflen,sizeof(char));
      
      mxGetString(prhs[1],cmd,buflen);
      mexEvalString(cmd);
      
      mxFree(cmd);
    }
    
    mxFree(fcn);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -