Matlab与C#混合编程

这篇博客详细介绍了如何在VS2010和Matlab r2009a环境下进行混合编程。首先,安装并更新Matlab,接着安装MCRInstall并配置环境变量。然后,设置编译器为Visual C++ 2008 SP1,并验证配置。接下来,编写M-file函数,最后通过Matlab Compiler创建.NET组件进行部署。整个过程包括多个步骤,需要耐心操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

      使用的软件环境为:VS2010、Matlab r2009a

       第一步:

    安装Matlab,我安装的MATLAB.v7.8.0.347.(R2009a).(Win32.云端版),安装时由于云端的版本有点低,安装之后需要更新才能使用,运行更新程序:CloudSetup1.0beta4_0903.exe,然后还需要注册。

      第二步:

         安装MCRInstall.exe,我安装完Matlab之后在这里找得的:D:"Program Files/MATLAB/R2009a/toolbox

/compiler/deploy/win32。然后还需要对MCRInstall进行环境配置。点击:我的电脑-属性-高级-环境变量-系统变量-PATH-编辑,在变量值输入框中,不要删除以前的字符串,在最前面加入MCR的安装路径,如:D:"Program Files/MATLAB/MATLAB Compiler Runtime/v80/bin/win32; 

         第三步:

      设置编译器。在命令窗口输入mbuild  -setup,回车继续配置,配置过程如下: 

       >> mbuild -setup

Please choose your compiler for building standalone MATLAB applications: 

 

Would you like mbuild to locate installed compilers [y]/n? n这里记得选择的是n

 

Select a compiler: 

[1] Lcc-win32 C 2.4.1 

[2] Microsoft Visual C++ 6.0 

[3] Microsoft Visual C++ .NET 2003 

[4] Microsoft Visual C++ 2005 SP1 

[5] Microsoft Visual C++ 2008 Express 

[6] Microsoft Visual C++ 2008 SP1 

 

[0] None 

 

Compiler: 6这个随自己电脑上安装的vs选择

 

The default location for Microsoft Visual C++ 2008 SP1 compilers is C:/Program Files/Microsoft Visual Studio 9.0, 

but that directory does not exist on this machine.  

 

Use C:/Program Files/Microsoft Visual Studio 9.0 anyway [y]/n? y  (这个是VS在系统盘中的路径

 

Please verify your choices: 

 

Compiler: Microsoft Visual C++ 2008 SP1  

Location: C:/Program Files/Microsoft Visual Studio 9.0 

 

Are these correct [y]/n? y

配置完成之后,会给出提示信息。

 

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

  Warning: Applications/components generated using Microsoft Visual Studio   

           2008 require that the Microsoft Visual Studio 2008 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:/Documents and Settings/Administrator/Application Data/MathWorks/MATLAB/R2009a/compopts.bat 

From template:              C:/PROGRA~1/matlab/r2009a/bin/win32/mbuildopts/msvc90compp.bat 

 

Done . . . 

       第四步:

   编写自己M-file,通常一个M-file里只包含一个函数,函数可以有输入输出。

       如:

       function y=MyAdd(a,b)

             y=a+b; 

     end

       第五步:

       在命令窗口中输入deploytool或者直接点左下角的Start—Matlab—Matlab Complier—Deployment Tool

(deploytool),新建一个 Deployment Project,选择“Matlab Builder NE”——“.Net Component”.(取名为

MyAdd)

      第六步:

       向MyAdd中加入第四步中写的M-file,然后编译,编译的时候需要好几分钟的时间,要耐心点了。

      

 

       

 


评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值