C++ 无法生成mex文件
我已经按照MATLAB示例从这里创建了一个C++ 无法生成mex文件,c++,matlab,C++,Matlab,我已经按照MATLAB示例从这里创建了一个mex文件 它产生的源代码如下 #include "mex.h" /* The computational routine */ void arrayProduct(double x, double *y, double *z, mwSize n) { mwSize i; /* multiply each element y by x */ for (i=0; i<n; i++) { z[i] = x *
mex
文件
它产生的源代码如下
#include "mex.h"
/* The computational routine */
void arrayProduct(double x, double *y, double *z, mwSize n)
{
mwSize i;
/* multiply each element y by x */
for (i=0; i<n; i++) {
z[i] = x * y[i];
}
}
/* The gateway function */
void mexFunction( int nlhs, mxArray *plhs[],
int nrhs, const mxArray *prhs[])
{
double multiplier; /* input scalar */
double *inMatrix; /* 1xN input matrix */
size_t ncols; /* size of matrix */
double *outMatrix; /* output matrix */
/* check for proper number of arguments */
if(nrhs!=2) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nrhs","Two inputs required.");
}
if(nlhs!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:nlhs","One output required.");
}
/* make sure the first input argument is scalar */
if( !mxIsDouble(prhs[0]) ||
mxIsComplex(prhs[0]) ||
mxGetNumberOfElements(prhs[0])!=1 ) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notScalar","Input multiplier must be a scalar.");
}
/* make sure the second input argument is type double */
if( !mxIsDouble(prhs[1]) ||
mxIsComplex(prhs[1])) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notDouble","Input matrix must be type double.");
}
/* check that number of rows in second input argument is 1 */
if(mxGetM(prhs[1])!=1) {
mexErrMsgIdAndTxt("MyToolbox:arrayProduct:notRowVector","Input must be a row vector.");
}
/* get the value of the scalar input */
multiplier = mxGetScalar(prhs[0]);
/* create a pointer to the real data in the input matrix */
inMatrix = mxGetPr(prhs[1]);
/* get dimensions of the input matrix */
ncols = mxGetN(prhs[1]);
/* create the output matrix */
plhs[0] = mxCreateDoubleMatrix(1,(mwSize)ncols,mxREAL);
/* get a pointer to the real data in the output matrix */
outMatrix = mxGetPr(plhs[0]);
/* call the computational routine */
arrayProduct(multiplier,inMatrix,outMatrix,(mwSize)ncols);
}
#包括“mex.h”
/*计算程序*/
空阵列产品(双x、双y、双z、MWN)
{
MWi尺寸;
/*将每个元素y乘以x*/
对于(i=0;i来说,是MSVC Professional 2015。另外,。您的编译器可能是MSVC 2017,64位
尝试安装.NET4+sdk7.1,在MATLAB中选择它,然后重新运行mex
命令。这是一个官方支持的R2015b编译器,我希望这能解决您的问题
注意:对我来说,.NET4拒绝安装,因为它检测到以前安装的框架,但为我解决了该问题。The。但是,即使这是问题的一部分,像您得到的链接错误也不是我所期望的错误……啊……您的编译器可能是MSVC 2017,64位。@Rodyoldenhui目前正在使用此修复程序来解决此问题让2015b支持2017编译器…这是修复R2016b/R2017a中一个错误的方法?尝试安装.NET4+SDK 7.1,在MATLAB中选择它,然后重新运行mex
命令--这是一个官方支持的编译器,我希望这能解决您的问题。