(1)mex -setup 选择编译器
#include "mex.h"
void mexFunction(int nlhs,mxArray* plhs[],int nrhs,const mxArray* prhs[])
{
mexPrintf("Hello, matlab withcuda!\n");
}
这里的mexFunction只是一种接口函数,是必须存在的,通过它可以调用我们自己的函数,下面这个例子更充分一点:
#include "mex.h"
//计算过程
void hilb(double *y,int n)
{
}
//接口过程
void mexFunction(int nlhs,mxArray *plhs[],int nrhs,const mxArray *prhs[])
{
}
参数nlhs和nrhs表示MATLAB在调用该MEX文件时等式左端和右端变量的个数,例如在MATLAB命令窗口中输入以下命令:
[a,b,c]=Matlab_1(d,e,f,g)。则nlhs为3,nrhs为4。
MATLAB在调用MEX文件时,输入和输出参数保存在两个mxArray*类型的指针数组中,分别为prhs[]和plhs[]。prhs[0]表示第一个输入参数,prhs[1]表示第二个输入参数,…,以此类推。