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

📄 li1.txt

📁 这是机械工业张德丰《MATLAB与外部程序接口编程》随书源码
💻 TXT
字号:
# include “math.h”
void timestwo(double y[ ],double x[ ])
{
y[0]=2.0*x[0];
return;
}


# include “mex.h”
void timestwo(double y[ ],doublex[ ])
{
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(“需要一个输入参数.”);
}
else 
if(nlhs>1)
{
mexErrMsgTxt(“输出参数太多.”);
}
/*输入变量必须是非复数类型的标题*/
mrows=mxGetM(prhs[0]);
ncols=mxGetN(prhs[[0]);
if(!mxIsDouble(prhs[0]) || mxIsComplex(prhs[0]) || !(mrows= =1 && ncols= =1))
{
mexErrMsgTxt(“输入变量必须是非复数类型的标量.”);
}
/*为返回参数创建矩阵*/
plhs[0]=mxCreateDoubleMatrix(mrows,ncols,mxPEAL);
/*分配输入/输出参数的指针*/
x=mxGetPr(prhs[0]);
y=mxGetPr(plhs[0]);
/*调用timestwo子函数*/
timestwo(y,x);
}

⌨️ 快捷键说明

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