您的位置:首页 > 编程语言 > MATLAB

Matlab与C#混合编程

2010-11-11 17:49 281 查看
使用的软件环境为: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,然后编译,编译的时候需要好几分钟的时间,要耐心点了。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: