Matlab VC 联合编程 控制台以及MFC中实现(二)

这里首先对matlab以及vc进行配置,并介绍一下在哪里可以查到相应的帮助文档.

Matlab使用的是2010a,VC使用的是Visual Studio 2005,

Matlab Compiler安装,直接运行mbuild –setup指令,这时按照如下来运行:

clip_image001[5]

> >   mbuild   - setup
 
Please   choose   your   compiler   for   building   standalone   MATLAB   applications :  
 
Would   you   like   mbuild   to   locate   installed   compilers   [y] / n?   y  
 
Select   a   compiler :  
 
[ 1 ]   Lcc - win32   C   2 . 4 . 1   in   D : /Matlab/sys/lcc  
10   
11  [ 2 ]   Microsoft   Visual   C + +   2005   SP1   in   C : /Program   Files/Microsoft   Visual   Studio   8  
12   
13  [ 0 ]   None
14   
15  Compiler :   2
16   
17  Please   verify   your   choices :  
18   
19  Compiler :   Microsoft   Visual   C + +   2005   SP1
20   
21  Location :   C : /Program   Files/Microsoft   Visual   Studio   8  
22   
23  Are   these   correct   [y] / n?  
24   
25  Trying   to   update   options   file :   C : /Users/Administrator/AppData/Roaming/MathWorks/MATLAB/R2010a/compopts . bat  
26   
27  From   template :   D : /Matlab/bin/win32/mbuildopts/msvc80compp . bat  
28   
29  Done   .   .   .
30   
31   

实际上就是选择对应的编译器,选择好了等着安装完成就可以了.

VS2005配置,就是在工具->选项->项目和解决方案->VC++目录->包含文件中包含matlab文件夹下extern/include目录,以及库文件中包含/extern/lib/win32/microsoft目录

clip_image003[4]

clip_image005[4]

在写程序时需要加入matlab的一些lib文件,可以在项目属性->配置属性->链接器->输入->附加依赖项中进行设置,不过为了避免每一个项目都进行设定,这里将lib文件包含到一个头文件中,每个项目只需要包含该头文件即可.同时考虑到matlab程序可能调用matlab中的各种函数,最好是将/extern/lib/win32/microsoft目录下的所有lib文件都包含进去.这里写的matlab_header.h如下:

#pragma   once
 
#pragma   comment(lib,   " mclmcr.lib " )
 
#pragma   comment(lib,   " libmwlapack.lib   " )
 
#pragma   comment(lib,   " mclcommain.lib " )
 
#pragma   comment(lib,   " libmwblascompat32.lib   " )
10   
11  #pragma   comment(lib,   " rtwcg.lib " )
12   
13  #pragma   comment(lib,   " libut.lib   " )
14   
15  #pragma   comment(lib,   " libmwblas.lib " )
16   
17  #pragma   comment(lib,   " physmod_foundation_util.lib " )
18   
19  #pragma   comment(lib,   " libmx.lib   " )
20   
21  #pragma   comment(lib,   " libmex.lib   " )
22   
23  #pragma   comment(lib,   " ne_rtl.lib " )
24   
25  #pragma   comment(lib,   " libmwsl_solver_rtw.lib " )
26   
27  #pragma   comment(lib,   " libmat.lib " )
28   
29  #pragma   comment(lib,   " ne_mli.lib " )
30   
31  #pragma   comment(lib,   " libmwsl_fileio.lib   " )
32   
33  #pragma   comment(lib,   " libfixedpoint.lib " )
34   
35  #pragma   comment(lib,   " mclxlmain.lib " )
36   
37  #pragma   comment(lib,   " libmwservices.lib " )
38   
39  #pragma   comment(lib,   " libeng.lib " )
40   
41  #pragma   comment(lib,   " mclmcrrt.lib " )
42   
43  #pragma   comment(lib,   " libmwmathutil.lib " )
44   
45  #pragma   comment(lib,   " libemlrt.lib " )
46   
47   

后面写的所有调用matlab函数的程序只需要包含该头文件即可.

Matlab中有用的帮助文档,Matlab Compiler下面的帮助很长………….这里列出一部分个人认为非常有用的,

第一个是一段视频demo,网址为http://www.mathworks.com/support/2010a/compiler/4.13/demos/using-MATLAB-Compiler.html

这段讲怎么用deploytool将一段matlab代码编译成C++的接口函数

第二个是Matlab Compiler->User Guide->Libraries->MATLAB Compiler Generated Interface Functions

这段以一个实例讲解了怎么调用接口函数,其中最重要的一段如下:

Structure of Programs That Call Shared Libraries

All programs that call MATLAB Compiler generated shared libraries have roughly the same structure:

  1. Declare variables and process/validate input arguments.
  2. Call mclInitializeApplication, and test for success. This function sets up the global MCR state and enables the construction of MCR instances.
  3. Call, once for each library, <libraryname>Initialize, to create the MCR instance required by the library.
  4. Invoke functions in the library, and process the results. (This is the main body of the program.)
  5. Call, once for each library, <libraryname>Terminate, to destroy the associated MCR.
  6. Call mclTerminateApplication to free resources associated with the global MCR state.
  7. Clean up variables, close files, etc., and exit.

To see these steps in an actual example, review the main program in this example, triangle.c .

讲解了整个程序的流程

第三个是Matlab Compiler->User Guide-> C++ Utility Library Reference

这里讲解了Matlab中的数据类型,尤其是mwArray

第四个是Matlab Compiler->Functions

主要讲解了如何调用一些函数.

第五个是Matlab->User Guide-> C/C++ and Fortran API Reference

也有一些函数可以参考

 

所有源程序在这里可以下到 http://download.csdn.net/source/2827645    

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值