设为首页 加入收藏

TOP

C++和MATLAB混合编程(一)
2013-11-20 14:24:29 来源: 作者: 【 】 浏览:255
Tags:MATLAB 混合 编程

  最近做的项目用到很多数字信号处理的知识。因为对这部分并不特别熟悉,编程有很大限制,而MATLAB提供了丰富的数字信号处理工具箱,于是MATLAB就成了很好的选择。

  在尝试将MATLAB程序整合到C++中时,遇到不少问题,特开此题。

  MATLAB在7.0以后使用MCR(Matlab Compiler Runtime)以及CTF(Component Technology File)技术。以前的编译器侧重将MATLAB程序编译成C/C++程序(像MATCOM4.5那样),但后来侧重编译为MCR可执行程序。

  这里插一小段:Matlab的代码编写很简单,元素也比C++少得多,所以从原理上说把MATLAB代码翻译成C++是完全可行的,MATCOM就是采用这一策略,而且还自己提供了一套MATCOM矩阵运算数学库,在C++中可以像用math.c中的算法一样用MATCOM的算法。然后可以遇见,这样发展下去的一大问题就是MATLAB核心代码都会公之于众,于是MATLAB收购了MATCOM,并通过MCR技术解决了这一问题。注意现在编译后只是提供接口文件,而非核心算法的C++代码。不过仍有很多工具箱是不能通过Matlab编译的。

  MCR实际是Matlab提供的动态链接库,可以在未安装Matlab的机器上运行Maltab的程序。CTF是将最终要发布的程序打包为cft文件(此文件进行了代码加密)。通过编译的可执行程序或东来链接库文件或COM组件,在执行(或被主程序调用)时会自动把编译的MATLAB代码传递给MCR执行。

  使用MATLAB编译器:

  在MATLAB运行mbuild -setup命令,出现如下信息:

  >> 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:

   Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010b\sys\lcc

   Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0

   Microsoft Visual C++ 2008 SP1 in C:\Program Files\Microsoft Visual Studio 9.0

  [0] None

  Compiler: 2

  Please verify your choices:

  Compiler: Microsoft Visual C++ 2010

  Location: C:\Program Files\Microsoft Visual Studio 10.0

  Are these correct [y]/n y

  ****************************************************************************

  Warning: Applications/components generated using Microsoft Visual C++

  2010 require that the Microsoft Visual Studio 2010 run-time

  libraries be available on the computer used for deployment.

  To redistribute your applications/components, be sure that the

  deployment machine has these run-time libraries.

  ****************************************************************************

  Trying to update options file: C:\Users\IDM\AppData\Roaming\MathWorks\MATLAB\R2010b\compopts.bat

  From template: C:\PROGRA~1\MATLAB\R2010b\bin\win32\mbuildopts\msvc100compp.bat

  Done . . .

  >> 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:

   Lcc-win32 C 2.4.1 in C:\PROGRA~1\MATLAB\R2010b\sys\lcc

   Microsoft Visual C++ 2010 in C:\Program Files\Microsoft Visual Studio 10.0

   Microsoft Visual C++ 2008 SP1 in C:\Program Files\Microsoft Visual Studio 9.0

  [0] None

  Compiler: 2

  Please verify your choices:

  Compiler: Microsoft Visual C++ 2010

  Location: C:\Program Files\Microsoft Visual Studio 10.0

  Are these correct [y]/n y

  ****************************************************************************

  Warning: Applications/components generated using Microsoft Visual C++

  2010 require that the Microsoft Visual Studio 2010 run-time

  libraries be available on the computer used for deployment.

  To redistribute your applications/components, be sure that the

  deployment machine has these run-time libraries.

  ****************************************************************************

  Trying to update options file: C:\Users\IDM\AppData\Roaming\MathWorks\MATLAB\R2010b\compopts.bat

  From template: C:\PROGRA~1\MATLAB\R2010b\bin\win32\mbuildopts\msvc100compp.bat

  Done . . .

   

首页 上一页 1 2 下一页 尾页 1/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇C++中new和delete的几点说明 下一篇顺序栈 Stack

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容:

·Libevent C++ 高并发 (2025-12-26 00:49:30)
·C++ dll 设计接口时 (2025-12-26 00:49:28)
·透彻理解 C 语言指针 (2025-12-26 00:22:52)
·C语言指针详解 (经典 (2025-12-26 00:22:49)
·C 指针 | 菜鸟教程 (2025-12-26 00:22:46)