下载matlab支持的mingw版本,不支持感觉也就是出个警告,问题不大,注意需要下载x86_64的版本,否则matlab不识别,下载路径如下:
https://sourceforge.net/projects/mingw-w64/files/
解压后放置到一个路径如D:\MINGW,后面的环境变量配置要用到这个位置
配置环境变量:
在我的电脑上点右键-》属性-》高级系统设置-》
在path变量中加入一项,注意这里要根据自己实际放置的位置来
D:\MinGW\bin
测试一下:
在matlab中输入:
系统检测到不同的编译器后,会提示如何将某个编译器配置为mex编译器,按照提示命令执行即可。
测试matlab自带示例程序:
/*=================================================================
* mexfunction.c
*
* This example demonstrates how to use mexFunction. It returns
* the number of elements for each input argument, providing the
* function is called with the same number of output arguments
* as input arguments.
* This is a MEX-file for MATLAB.
* Copyright 1984-2018 The MathWorks, Inc.
* All rights reserved.
*=================================================================*/
#include "mex.h"
void mexFunction(int nlhs, mxArray* plhs[], int nrhs, const mxArray* prhs[]) {
int i;
/* Examine input (right-hand-side) arguments. */
mexPrintf("\n%d input argument(s).", nrhs);
for (i = 0; i < nrhs; i++) {
mexPrintf("\n\tInput Arg %i is of type:\t%s ", i, mxGetClassName(prhs[i]));
}
/* Examine output (left-hand-side) arguments. */
mexPrintf("\n\n%d output argument(s).\n", nlhs);
if (nlhs > nrhs)
mexErrMsgIdAndTxt("MATLAB:mexfunction:inputOutputMismatch",
"Cannot specify more outputs than inputs.\n");
for (i = 0; i < nlhs; i++) {
mwSize nel = mxGetNumberOfElements(prhs[i]);
#if MX_HAS_INTERLEAVED_COMPLEX
plhs[i] = mxCreateDoubleScalar((mxDouble)nel);
*mxGetDoubles(plhs[i]) = (mxDouble)mxGetNumberOfElements(prhs[i]);
#else
plhs[i] = mxCreateDoubleScalar((double)nel);
*mxGetPr(plhs[i]) = (double)mxGetNumberOfElements(prhs[i]);
#endif
}
}
虽然警告版本不支持但是也能用:
![在这里插入图片描述](https://img-blog.csdnimg.cn/direct/27bf7949a7b740b693a4c5f2c9c54e87.png#pic_center = 480x)
测试一下:
至此确认配置完成。