xtimesy.c

来自「MATLAB中MEX命令的两个程序例子, 有详细解释, 如何在MATLAB里面调」· C语言 代码 · 共 32 行

C
32
字号
#include "mex.h"


void xtimesy(double x[],double y[], double z[])
{
  z[0] = x[0]*y[0];
}

void mexFunction( int nlhs, mxArray *plhs[],
                  int nrhs, const mxArray *prhs[] )
{
  double *x,*y, *z;

  /* Check for proper number of arguments. */
  
  if(nrhs!=2) {
    mexErrMsgTxt("Two  inputs required.");
  } else if(nlhs>1) {
    mexErrMsgTxt("Too many  output arguments");
  }
  
   /* Create matrix for the return argument. */
    plhs[0] = mxCreateDoubleMatrix(1,1, mxREAL);
  
  x = mxGetPr(prhs[0]);
  y = mxGetPr(prhs[1]);
  z = mxGetPr(plhs[0]);
  
 /* Call the xtimesy subroutine. */
  xtimesy(x,y,z);
}

⌨️ 快捷键说明

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