环境:
操作系统:windows xp sp3
MATLAB:Version 7.1.0.246(R14) Service Pack 3
第一步:安装编译器(如果已经安装则可跳过此步)
在MATLAB中安装编译器的步骤见下面
>> 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 C version 2.4.1 in D:/MATLAB71/sys/lcc
[2] Microsoft Visual C/C++ version 6.0 in D:/Program Files/Microsoft Visual Studio
[0] None
Compiler: 2
Please verify your choices:
Compiler: Microsoft Visual C/C++ 6.0
Location: D:/Program Files/Microsoft Visual Studio
Are these correct?([y]/n): y
Try to update options file: C:/Documents and Settings/Administrator/Application Data/MathWorks/MATLAB/R14SP3/compopts.bat
From template: D:/MATLAB71/BIN/win32/mbuildopts/msvc60compp.bat
Done . . .
--> ""D:/MATLAB71/bin/win32/mwregsvr" "D:/MATLAB71/bin/win32/mwcomutil.dll""
DllRegisterServer in D:/MATLAB71/bin/win32/mwcomutil.dll succeeded
--> ""D:/MATLAB71/bin/win32/mwregsvr" "D:/MATLAB71/bin/win32/mwcommgr.dll""
DllRegisterServer in D:/MATLAB71/bin/win32/mwcommgr.dll succeeded
>>
第二步:生成COM
生成COM的步骤如下
1、在命令窗口输入 "comtool” ,弹出MATLAB Builder对话框如图1。
图1
2、依次点击 "File”->"New Project..." 会弹出 New Project Settings 对话框,如图2。
图2
3、输入相关信息,如图3,点击 "OK" 按钮创建一个项目。
图3
4、此时 MATLAB Builder 对话框中会出现刚才新建的项目,如图4。
图4
5、现在就可以将我们实现写好的函数(.m文件)添加到项目中指定的类中。现我们向TestClass类中添加一个Test函数,如图5。
图5
6、依次点击 "Build"->"COM Object",MATLAB Builder开始生成COM对象,生成结果如图6。
图6
至此COM组建生成,我们就将MATLAB的函数打包成COM组建中的方法。