編譯環境:Microsoft Visual Studio 2008
版本 9.0.21022.8 RTM
Microsoft .NET Framework
版本 3.5
已安裝的版本: Professional
Microsoft Visual Basic 2008? ?91986-031-5000002-60050
Microsoft Visual Basic 2008
Microsoft Visual C# 2008? ?91986-031-5000002-60050
Microsoft Visual C# 2008
Microsoft Visual C++ 2008? ?91986-031-5000002-60050
Microsoft Visual C++ 2008
Microsoft Visual Studio 2008 Tools for Office? ?91986-031-5000002-60050
Microsoft Visual Studio 2008 Tools for Office
Microsoft Visual Web Developer 2008? ?91986-031-5000002-60050
Microsoft Visual Web Developer 2008
Crystal Reports? ? AAJ6G-K0MSA4K-680002Z
Crystal Reports Basic for Visual Studio 2008
Matlab 2008b
首先需要做的工作是matlab編譯器的設置,設置方法為:在Command window中輸入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
[5] Microsoft Visual C++ 2005 Express Edition
[6] Microsoft Visual C++ 2008
[0] None
Compiler: 6? ?? ?? ?? ?? ?? ?? ?? ?? ???%選擇6,其他編譯器可以選相應的選項,我沒有驗證過
The default location for Microsoft Visual C++ 2008 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? n%選擇n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9.0] D:\Program Files\Microsoft Visual Studio 9.0 %選擇您自己的當前安裝路徑
Please verify your choices:
Compiler: Microsoft Visual C++ 2008
Location: D:\Program Files\Microsoft Visual Studio 9.0
Are these correct [y]/n? y??%看上述信息,如果正確選擇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\R2008b\compopts.bat
From template:? ?? ?? ?? ???D:\PROGRA~1\MATLAB\R2008b\bin\win32\mbuildopts\msvc90compp.bat
Done . . .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%至次編譯器設置完成%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在matlab的Command window中輸入:
>> deploytool
Matlab產生deployment tool配置窗口
單擊新建按鈕,新建工程------>選擇MATLAB Builder NE 選項卡----->選擇.NET Component并添加工程名eaqual(測試用名,其實工程名稱就是你導入C#后的命名空間名稱,Matlab會在當前工作目錄中新建文件夾文件夾名既為equal)---->點擊ADD File按鈕將你需要編譯的MATLAB函數添加進當前工程,我這里導入的是 D:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m文件---->點擊build.
deployment tool output 窗口輸出以下信息:
Build output( 2009-03-28 15:32:55).
[url=matlab:mcc%20-F%20%27E:%5CMATLAB%5Ceaqual.prj%27]mcc -F 'E:\MATLAB\eaqual.prj'[/url]
等待...................................有點久
當輸出以下信息時編譯成功了
Compiler version: 4.9 (R2008b) Warning: Duplicate directory name: E:\MATLAB. mcc -W 'dotnet:eaqual,Eaqual,0.0,private' -d 'E:\MATLAB\eaqual\src' -T 'link:lib' -v 'class{Eaqual
:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m}' Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Processing D:\Program Files\MATLAB\R2008b\toolbox\aero\mcc.enc Processing D:\Program Files\MATLAB\R2008b\toolbox\matlab\mcc.enc Processing include files... 2 item(s) added. Processing directories installed with MCR... The file E:\MATLAB\eaqual\src\mccExcludedFiles.log contains a list of functions excluded from the CTF archive. 2 item(s) added. Generating MATLAB path for the compiled application... Created 40 path items. Begin validation of MEX files: Sat Mar 28 15:35:11 2009 End validation of MEX files: Sat Mar 28 15:35:11 2009 Warning: Name is nonexistent or not a directory: D:\Program Files\MATLAB\R2008b\toolbox\compiler\patch. Deleting 0 temporary MEX authorization files. Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m" (Referenced from: "Compiler Command Line"). Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\compiler\deploy\deployprint.m" (Referenced from: "Compiler Command Line"). Parsing file "D:\Program Files\MATLAB\R2008b\toolbox\compiler\deploy\printdlg.m" (Referenced from: "Compiler Command Line"). Generating file "E:\MATLAB\eaqual\src\Eaqual.cs". Generating file "E:\MATLAB\eaqual\src\EaqualNative.cs". Generating file "E:\MATLAB\eaqual\src\readme.txt". Generating file "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs". Executing command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"E:\MATLAB\eaqual\src\eaqual.xml" /t:library /r:"D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /resource:"E:\MATLAB\eaqual\src\eaqual.ctf" /out:"E:\MATLAB\eaqual\src\eaqual.dll" "E:\MATLAB\eaqual\src\Eaqual.cs" "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs" Executing command: C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\csc.exe /nologo /optimize /doc:"E:\MATLAB\eaqual\src\eaqualNative.xml" /t:library /r:"D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll" /resource:"E:\MATLAB\eaqual\src\eaqual.ctf" /out:"E:\MATLAB\eaqual\src\eaqualNative.dll" "E:\MATLAB\eaqual\src\EaqualNative.cs" "E:\MATLAB\eaqual\src\dotnet_mcc_component_data.cs" ??
Copying: E:\MATLAB\eaqual\src\eaqual.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\eaqualNative.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\readme.txt -> E:\MATLAB\eaqual\distrib
Compilation completed succesfully. The output is located in E:\MATLAB\eaqual\distrib.
You can package the component by clicking on the "
ackage" icon in the Deployment Tool toolbar, or by clicking the Tools->
ackage menu when the Deployment Tool panel is selected. To include additional files in the package, click Project->Settings).
生成的文件在工程文件夾里面
我的是??E:\MATLAB\eaqual\distrib\angle2quat.dll
至此MATLAB的操作全部完成
打開VISUAL Studio 2008新建C#工程我這里用的是控制臺名為TestOfmatlab_consolt
我的是??E:\Visual Studio 2008\Projects\TEST\TestOfmatlab_consolt
添加引用E:\MATLAB\eaqual\distrib\angle2quat.dll
和D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll
(這里我沒有用MATLAB畫圖,所以只引用MWArray.dll)
加入命名空間:
using MathWorks.MATLAB.NET.Arrays;
將下面代碼加入Main函數
? ?? ?? ?? ?eaqual.Eaqual eq=new eaqual.Eaqual();
? ?? ?? ?? ?MathWorks.MATLAB.NET.Arrays.MWArray m=10,n=4,j=7,k;
? ?? ?? ???
? ?? ?? ?? ? MWArray S = "XYZ";
? ?? ?? ?? ?k = eq.angle2quat((MWNumericArray)m, (MWNumericArray)n, (MWNumericArray)j,
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? (MWCharArray)S);
? ?? ?? ?? ?MWNumericArray temp = (MWNumericArray)k;
? ?? ?? ?? ?double[,] location = (double[,])temp.ToArray(MWArrayComponent.Real);
? ?? ?? ?? ?Console.WriteLine(location[0,0].ToString());
? ?? ?? ?? ?Console.WriteLine(location[0,1].ToString());
? ?? ?? ?? ?Console.WriteLine(k[2].ToString());
? ?? ?? ?? ?Console.WriteLine(k[3].ToString());
? ?? ?? ?? ?Console.WriteLine(k[4].ToString());
? ?? ?? ?? ?Console.ReadLine();
編譯運行即可看到輸出,此函數是姿態角轉四元數函數,具體功能就不做說明了。這個例子輸入輸出參數的轉換關系都有,大家自己看看就明白了
文件源代碼:C#工程源碼
由于工程文件過大就只把主函數源碼傳上來了!
版本 9.0.21022.8 RTM
Microsoft .NET Framework
版本 3.5
已安裝的版本: Professional
Microsoft Visual Basic 2008? ?91986-031-5000002-60050
Microsoft Visual Basic 2008
Microsoft Visual C# 2008? ?91986-031-5000002-60050
Microsoft Visual C# 2008
Microsoft Visual C++ 2008? ?91986-031-5000002-60050
Microsoft Visual C++ 2008
Microsoft Visual Studio 2008 Tools for Office? ?91986-031-5000002-60050
Microsoft Visual Studio 2008 Tools for Office
Microsoft Visual Web Developer 2008? ?91986-031-5000002-60050
Microsoft Visual Web Developer 2008
Crystal Reports? ? AAJ6G-K0MSA4K-680002Z
Crystal Reports Basic for Visual Studio 2008
Matlab 2008b
首先需要做的工作是matlab編譯器的設置,設置方法為:在Command window中輸入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
[5] Microsoft Visual C++ 2005 Express Edition
[6] Microsoft Visual C++ 2008
[0] None
Compiler: 6? ?? ?? ?? ?? ?? ?? ?? ?? ???%選擇6,其他編譯器可以選相應的選項,我沒有驗證過
The default location for Microsoft Visual C++ 2008 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? n%選擇n
Please enter the location of your compiler: [C:\Program Files\Microsoft Visual Studio 9.0] D:\Program Files\Microsoft Visual Studio 9.0 %選擇您自己的當前安裝路徑
Please verify your choices:
Compiler: Microsoft Visual C++ 2008
Location: D:\Program Files\Microsoft Visual Studio 9.0
Are these correct [y]/n? y??%看上述信息,如果正確選擇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\R2008b\compopts.bat
From template:? ?? ?? ?? ???D:\PROGRA~1\MATLAB\R2008b\bin\win32\mbuildopts\msvc90compp.bat
Done . . .
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%至次編譯器設置完成%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
在matlab的Command window中輸入:
>> deploytool
Matlab產生deployment tool配置窗口
單擊新建按鈕,新建工程------>選擇MATLAB Builder NE 選項卡----->選擇.NET Component并添加工程名eaqual(測試用名,其實工程名稱就是你導入C#后的命名空間名稱,Matlab會在當前工作目錄中新建文件夾文件夾名既為equal)---->點擊ADD File按鈕將你需要編譯的MATLAB函數添加進當前工程,我這里導入的是 D:\Program Files\MATLAB\R2008b\toolbox\aero\aero\angle2quat.m文件---->點擊build.
deployment tool output 窗口輸出以下信息:
Build output( 2009-03-28 15:32:55).
[url=matlab:mcc%20-F%20%27E:%5CMATLAB%5Ceaqual.prj%27]mcc -F 'E:\MATLAB\eaqual.prj'[/url]
等待...................................有點久
當輸出以下信息時編譯成功了
Compiler version: 4.9 (R2008b) Warning: Duplicate directory name: E:\MATLAB. mcc -W 'dotnet:eaqual,Eaqual,0.0,private' -d 'E:\MATLAB\eaqual\src' -T 'link:lib' -v 'class{Eaqual

Copying: E:\MATLAB\eaqual\src\eaqual.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\eaqualNative.dll -> E:\MATLAB\eaqual\distrib
Copying: E:\MATLAB\eaqual\src\readme.txt -> E:\MATLAB\eaqual\distrib
Compilation completed succesfully. The output is located in E:\MATLAB\eaqual\distrib.
You can package the component by clicking on the "


生成的文件在工程文件夾里面
我的是??E:\MATLAB\eaqual\distrib\angle2quat.dll
至此MATLAB的操作全部完成
打開VISUAL Studio 2008新建C#工程我這里用的是控制臺名為TestOfmatlab_consolt
我的是??E:\Visual Studio 2008\Projects\TEST\TestOfmatlab_consolt
添加引用E:\MATLAB\eaqual\distrib\angle2quat.dll
和D:\Program Files\MATLAB\R2008b\toolbox\dotnetbuilder\bin\win32\v2.0\MWArray.dll
(這里我沒有用MATLAB畫圖,所以只引用MWArray.dll)
加入命名空間:
using MathWorks.MATLAB.NET.Arrays;
將下面代碼加入Main函數
? ?? ?? ?? ?eaqual.Eaqual eq=new eaqual.Eaqual();
? ?? ?? ?? ?MathWorks.MATLAB.NET.Arrays.MWArray m=10,n=4,j=7,k;
? ?? ?? ???
? ?? ?? ?? ? MWArray S = "XYZ";
? ?? ?? ?? ?k = eq.angle2quat((MWNumericArray)m, (MWNumericArray)n, (MWNumericArray)j,
? ?? ?? ?? ?? ?? ?? ?? ?? ?? ? (MWCharArray)S);
? ?? ?? ?? ?MWNumericArray temp = (MWNumericArray)k;
? ?? ?? ?? ?double[,] location = (double[,])temp.ToArray(MWArrayComponent.Real);
? ?? ?? ?? ?Console.WriteLine(location[0,0].ToString());
? ?? ?? ?? ?Console.WriteLine(location[0,1].ToString());
? ?? ?? ?? ?Console.WriteLine(k[2].ToString());
? ?? ?? ?? ?Console.WriteLine(k[3].ToString());
? ?? ?? ?? ?Console.WriteLine(k[4].ToString());
? ?? ?? ?? ?Console.ReadLine();
編譯運行即可看到輸出,此函數是姿態角轉四元數函數,具體功能就不做說明了。這個例子輸入輸出參數的轉換關系都有,大家自己看看就明白了
文件源代碼:C#工程源碼
由于工程文件過大就只把主函數源碼傳上來了!