📄 timestwo.c
字号:
/* timestwo.c */
#include "math.h"
void timestwo(double y[], double x[])
{
y[0]=2.0 * x[0];
}
void mexFunction(int nlhs,mxArray *plhs[ ],int nrhs,const mxArray *prhs[ ])
{
double *x, *y;
int mrows,ncols;
//检查参数数目是否正确
if(nrhs!=1)
{
mexErrMsgTxt("One input required.");
}
else if(nlhs>1)
{
mexErrMsgTxt("Too many output arguments");
}
//输入参数必须是一个非复数的双精度数值
mrows=mxGetM(prhs[0]);
ncols=mxGetN(prhs[0]);
if(!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows = = 1 && ncols = = 1))
{
mexErrMsgTxt("Input must be a noncomplex scalar double.");
}
//创建返回参数矩阵
plhs[0]=mxCreateDoubleMatrix(mrows,ncols,mxREAL);
//给各输入输出参数赋指针
x=mxGetPr(prhs[0]);
y=mxGetPr(plhs[0]);
//调用子函数timestwo
timestwo(y,x);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -