matlab建立mex,Visual Studio创建Matlab mex(dll)函数
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,Visual Studio创建Matlab mex(dll)函数相关推荐
- 在matlab中如何打开示例程序,visual studio 调用 matlab实例
续接上篇,本文将对如何通过visual studio调用matlab画图做出指导, 并给出实例. 代码部分: 首先在头文件补充engine #include"engine.h" 然 ...
- Matlab 2019a 与 Visual Studio 2017 联合编译
因为要用NYU V2 ToolBox中的 深度补全 功能,所以接触到了如题的点.如下图所示,ToolBox代码有放在Matlab中运行的 .m 文件,也有经典的 .cpp 文件.简单科普一下,因为 C ...
- 解决 Visual Studio 2017 RC 不兼容低版本 Visual Studio 创建的 MVC 4 项目的问题
解决 Visual Studio 2017 RC 不兼容低版本 Visual Studio 创建的 MVC 4 项目的问题 参考文章: (1)解决 Visual Studio 2017 RC 不兼容低 ...
- Xamarin XAML语言教程使用Visual Studio创建XAML
Xamarin XAML语言教程使用Visual Studio创建XAML Xamarin.Forms允许开发人员通过XAML语法对程序的所有用户界面元素进行详细的定制,如文本.按钮.图像和列表框等. ...
- visual studio创建项目时需要注意的问题
visual studio创建项目时需要注意的问题 Win32项目中,只能使用WinMain函数 . Win32控制台程序中只能使用main函数 .
- Xamarin 中Visual Studio创建项目提示错误
Xamarin 中Visual Studio创建项目提示错误 错误信息:Object reference not set to an instance of an object 出现这种情况,是由于没 ...
- 使用Visual Studio 创建新的Web Part项目
使用Visual Studio 创建新的Web Part项目 Web Part是你将为SharePoint创建的最常见的对象之一.它是平台构建的核心基块. 1. 管理员身份打开Visual Studi ...
- 使用Visual Studio 创建可视Web Part部件
使用Visual Studio 创建可视Web Part部件 可视Web Part部件是很强大的Web 部件.它提供内置设计器创建你的用户界面. 本文主要解说怎样使用Visual Studio 创建可 ...
- 如何使用Visual Studio创建SQL Server数据库项目
目录 背景 介绍 创建新的SQL Server数据库项目 发布以在SQL Server中创建新数据库 结论 背景 数据库在任何应用程序中都扮演着最重要的角色,当表.视图.存储过程的数量增加时,项目管理 ...
最新文章
- Java集合框架综述,这篇让你吃透!
- 嵌入式linux文件系统
- hive sqoop 分区导入_利用oozie,执行sqoop action将DB2中的数据导入到hive分区表中
- C语言按各科分数段统计人数,(更新啦)学校学生成绩统计通用模板(科目、分数、统计分数段等均可自定,班级数、学生人数不受限制)...
- win7卸载python2.7_win7重装系统后设置Python2.7环境
- php是否支持64位,phpstudy默认不支持64位php的解决方法
- 干掉13个区块链最常见的Bug!
- Android 面试自我介绍
- 什么是 Rax,以及 Rax 的特点
- Android各版本源码网盘下载(不断更新)
- 微信小程序-更换头像
- mpvue + vuex搭建小程序详细教程
- 显示seata连接不上127.0.0.1:2181
- 关于CFD计算过程的梳理
- 老夫整理的1000行MySQL学习笔记传授有缘人
- Map大家族的那点事儿(一) Map
- 爱我专业计算机,计算机-我最爱的专业 选你无悔
- 使用node ftp上传文件夹到
- .net 字符串逗号隔开去重
- android应用换字体,Android手机字体随意换-字体管家
热门文章
- mysql errorcode 1366_mysql插入emoji表情报 error code [1366]
- 一文说清“链上”和“链下”
- OSError: [WinError 145] 目录不是空的。
- IT系统管理员的节日
- 【Java系列】数据库系统的可视化界面开发
- Google Authenticator windows client 谷歌身份验证器 windows 电脑端
- Scala语法小练习(银行小程序)
- eclipse 项目有红叉(解决方法)
- 怎么给自己的html网页加个密码,密码正确才能显示网页
- RT-Thread学习笔记五——临界区与临界区保护