7). 然后打开project

-> test_matlab_3 properties -> C++

-> Code Generation -> Runtime

Library,选择 Multi-threaded Debug (/MTd)。

8). 然后打开project -> test_matlab_3 properties

-> Linker -> Input ->

Additional Dependencies中添加

libmx.lib,libmat.lib,libmex.lib,libeng.lib。

9).

然后打开project -> test_matlab_3 properties

-> Linker -> Input ->

Module Definition File中添加 .\mexFunction.def。

10).

然后打开project -> add new item,添加Module-Definition File

文件名为mexFunction.def。文件代码后附。

11).

然后打开project -> add new item,添加Header File

文件名为mexFunction.h。文件代码后附。

12).

编译,链接,生成test_matlab_3.dll文件,也就是我们想要的mex文件。

13).

将生成的文件拷贝到matlab目录下,执行"test_matlab_3(1,'Panpan Hu')",返回如下结果

注意:本质上来讲mex和dll没有区别,只是两个不同的后缀名。Matlab2010b以后版本可能不支持调用dll为后缀的mex文件。消息来源如下

A MEX-file is a shared library dynamically loaded at runtime.

Shared libraries are sometimes called .dll files, for

dynamically-linked library. MEX-files have a platform-dependent

extension, which the mex function automatically

assigns.

On 32-bit Windows platforms, the extension is .mexw32.

MATLAB has supported .dll as a secondary MEX-file

extension since Version 7.1 (R14SP3). In Version 7.7 (R2008b), if

you used the -output switch to create a MEX-file with a

.dll extension, MATLAB displayed a warning message that

such usage is being phased out.

In MATLAB Version 7.10 (R2010a), you can no longer create a

MEX-file with a .dll file extension. If you try to, MATLAB

creates the MEX-file with the proper extension and displays the

following warning:

Warning: Output file was specified with file extension, ".dll", which

is not a proper MEX-file extension. The proper extension for

this platform, ".mexw32", will be used instead.

MATLAB continues to execute a MEX-file with a .dll

extension, but future versions of MATLAB will not support this

extension.

本文参考如下网络资源

http://blog.sina.com.cn/s/blog_4d1865f00100o2ul.html

http://www.engineering.uiowa.edu/~dip/lecture/C++_with_Matlab.pdf

附录1 mexFunction.cpp

#include "mexFunction.h"

#include

#include "stdlib.h"

#include

using namespace std;

void mexFunction( int nlhs, mxArray *plhs[],int nrhs, const

mxArray*prhs[] )

{

double

*Encoder_Decoder_db = NULL;

string

Path_Str=""; // the path of the bands

unsigned int

bufferlength = mxGetM(prhs[1])*mxGetN(prhs[1])+1;

char

*Path_Str_ch = new char[bufferlength];

short

Encoder_Decoder; // 0: encoder, 1: decoder

Encoder_Decoder_db = mxGetPr(prhs[0]);

mxGetString(prhs[1], Path_Str_ch,

bufferlength); Encoder_Decoder = (short) *Encoder_Decoder_db;

Path_Str =

Path_Str + Path_Str_ch;

mexPrintf("\nBegin of Test-Zhao Wang 6.2.2011\n");

mexPrintf("%d, %s\n", Encoder_Decoder, Path_Str_ch);

mexPrintf("End of Test-Zhao Wang 6.2.2011\n");

}

附录2 mexFunction.h

#include "matrix.h"

#include "mex.h"

#define TEST_MATLAB_3_EXPORTS

#ifdef TEST_MATLAB_3_EXPORTS

#define MEX_FUNCTION_API __declspec(dllexport)

#else

#define MEX_FUNCTION_API __declspec(dllimport)

#endif

MEX_FUNCTION_API void mexFunction(int nlhs, mxArray* plhs[],int

nrhs, mxArray* prhs[]);

附录3 mexFunction.def

LIBRARY "test_matlab_3"

EXPORTS

mexFunction

matlab mex dll,Visual Studio创建Matlab mex(dll)函数相关推荐

  1. matlab建立mex,Visual Studio创建Matlab mex(dll)函数

    7). 然后打开project -> test_matlab_3 properties -> C++ -> Code Generation -> Runtime Library ...

  2. 在matlab中如何打开示例程序,visual studio 调用 matlab实例

    续接上篇,本文将对如何通过visual studio调用matlab画图做出指导, 并给出实例. 代码部分: 首先在头文件补充engine #include"engine.h" 然 ...

  3. Matlab 2019a 与 Visual Studio 2017 联合编译

    因为要用NYU V2 ToolBox中的 深度补全 功能,所以接触到了如题的点.如下图所示,ToolBox代码有放在Matlab中运行的 .m 文件,也有经典的 .cpp 文件.简单科普一下,因为 C ...

  4. 解决 Visual Studio 2017 RC 不兼容低版本 Visual Studio 创建的 MVC 4 项目的问题

    解决 Visual Studio 2017 RC 不兼容低版本 Visual Studio 创建的 MVC 4 项目的问题 参考文章: (1)解决 Visual Studio 2017 RC 不兼容低 ...

  5. Xamarin XAML语言教程使用Visual Studio创建XAML

    Xamarin XAML语言教程使用Visual Studio创建XAML Xamarin.Forms允许开发人员通过XAML语法对程序的所有用户界面元素进行详细的定制,如文本.按钮.图像和列表框等. ...

  6. visual studio创建项目时需要注意的问题

    visual studio创建项目时需要注意的问题 Win32项目中,只能使用WinMain函数 . Win32控制台程序中只能使用main函数 .

  7. Xamarin 中Visual Studio创建项目提示错误

    Xamarin 中Visual Studio创建项目提示错误 错误信息:Object reference not set to an instance of an object 出现这种情况,是由于没 ...

  8. 使用Visual Studio 创建新的Web Part项目

    使用Visual Studio 创建新的Web Part项目 Web Part是你将为SharePoint创建的最常见的对象之一.它是平台构建的核心基块. 1. 管理员身份打开Visual Studi ...

  9. 使用Visual Studio 创建可视Web Part部件

    使用Visual Studio 创建可视Web Part部件 可视Web Part部件是很强大的Web 部件.它提供内置设计器创建你的用户界面. 本文主要解说怎样使用Visual Studio 创建可 ...

  10. 如何使用Visual Studio创建SQL Server数据库项目

    目录 背景 介绍 创建新的SQL Server数据库项目 发布以在SQL Server中创建新数据库 结论 背景 数据库在任何应用程序中都扮演着最重要的角色,当表.视图.存储过程的数量增加时,项目管理 ...

最新文章

  1. 如何利用PopupWindow实现弹出菜单并解决焦点获取以及与软键盘冲突问题
  2. 皮一皮:别人家的老公...
  3. Eclipse设置字符编码
  4. 互联网控制报文协议(ICMP)
  5. Unfair contest(个人做法)
  6. java103 101 104 101_编写一个java程序将100,101,102,103,104,105这6个数以数组的形式写入到D:\\test.t...
  7. 红外图像盲元修正MATLAB算法,红外图像盲元检测方法与流程
  8. BLE蓝牙4.0串口调试助手
  9. Anki 也能用上思维导图了~
  10. win7显示u盘efi分区_win7下找不到u盘efi分区
  11. html中两个块之间有空隙,css标签之间引发空隙问题解决办法
  12. 使用web3.py获取zkSync中的数据
  13. 综论数据库防火墙的自我修养系列之一:高可用性
  14. efi分区格式化操作
  15. Date-如何获取自然天,自然周,自然月,自然年?
  16. python_生成器简介
  17. selenium录屏python_Selenium实现录屏的一种方法
  18. m0n0wall 软件防火墙 虚拟机中 安装与配置
  19. 第1章 基础:逻辑和证明 部分内容
  20. 非科班出身程序员,如何超越科班程序员?

热门文章

  1. 2020年4月全国自考计算机应用基础试卷,2020年4月自考计算机应用基础考前冲刺题及答案2...
  2. IBMV7000存储后台命令详解
  3. 【产品学习】从技术转型到产品的一些心得和建议
  4. 别让自己堕落成“老油条”
  5. Java微信插件开发培训—10月28日 晚九点—腾讯课堂
  6. 计算机2级广东2019报名时间,广东2019年计算机等级考试(NCRE)报名时间
  7. mysql 多个游标_如何在MySQL中的单个存储过程中使用多个游标
  8. 自动驾驶行业整合“加速”,能否快速规模化“扼杀”初创公司
  9. SHELL syntax error unexpected end of file 提示错误
  10. 视频时代,AI能做些什么