📄 ex0801.cpp
字号:
// Ex0801.cpp : Defines the entry point for the DLL application.
//
#include "mex.h"
#include "math.h"
void Ex0801(double y[],double x[])
{
y[0]=1/(x[0]*x[0]);
return;
}
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
double *x,*y;
unsigned int m,n;
/*检查输入变量个数是否正确*/
if(nrhs!=1)
{
mexErrMsgTxt("Only one input argument allowed.");
}
/*检查输出变量个数是否正确*/
else if(nlhs!=1){
mexErrMsgTxt("Only one output argument allowed.");
}
m = mxGetM(prhs[0]);
n = mxGetN(prhs[0]);
/*检查输入变量必须是非复数的常数*/
if (!mxIsDouble(prhs[0]) || mxIsSparse(prhs[0]) || mxIsComplex(prhs[0])||
! (m==1&&n==1))
{
mexErrMsgTxt("Input argument must be a scalar.");
}
/*创建矩阵变量作为输出变量*/
plhs[0]=mxCreateDoubleMatrix(m,n,mxREAL);
y = mxGetPr(plhs[0]);
x = mxGetPr(prhs[0]);
/*调用计算子程序Ex0801*/
Ex0801(y,x);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -