📄 double_add.c
字号:
#include "mex.h"
void double_add(double *z, double x, double y)
{
*z = x + y;
}
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[] )
{
/* 创建临时变量 */
double *z;
double x;
double y;
/* 检查参数 */
if (nrhs != 2) {
mexErrMsgTxt("Two input argument required.");
} else if (nlhs > 1) {
mexErrMsgTxt("Too many output arguments.");
} else if (!mxIsNumeric(prhs[0]) || !mxIsNumeric(prhs[1])) {
/* 需要检查两个输入参数x和y是否为数值型 */
mexErrMsgTxt("Both The Two Arguments must be numeric.");
} else if (mxGetNumberOfElements(prhs[0]) != 1 || mxIsComplex(prhs[0]) ||
mxGetNumberOfElements(prhs[1]) != 1 || mxIsComplex(prhs[1])) {
/* 需要检查两个输入参数x和y是否为标量 */
mexErrMsgTxt("Argument must be non-complex scalar.");
}
/* 为输出参数创建变量 */
plhs[0] = mxCreateDoubleMatrix(1,1,mxREAL);
x = mxGetScalar(prhs[0]);
y = mxGetScalar(prhs[1]);
z = mxGetPr(plhs[0]);
/* 调用double_add 子函数 */
double_add(z,x,y);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -