配置matlab中的mex编译环境为mingw

下载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)
测试一下:
在这里插入图片描述
至此确认配置完成。

  • 8
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

三环西北角

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值