Matlab(2013a)
VB6(VC、C#、Delphi 也可)
两台电脑(用VMWare搭建虚拟机也可)
选择 c/c++ 编译器
动部署工具,新建
为COM组件添加新类及类的输出函数
M文件源码
编译COM组件
完成编译
生成自解压安装包(本地使用的话,Matalb自动注册COM组件,无需发布; 但如果想要发布到没有安装Matlab的计算机上,则安装包中需添加Matab运行库 MCR,MCR安装一次即可,另外目标计算机上还需要有msjava.dll及VC运行库 msvcrt100.dll才能成功注册COM,系统环境缺失的常见dll文件可以用DirectX修复工具修复,或者在网上下载然后手动注册)
最终生成的自解压安装文件
部署到另一台没有Matlab的计算机上(例如Xp SP3,虚拟机也可)
利用VB6 引用COM组件进行实际开发(Delphi /VC / .Net 均可引用)
VB6 测试 Demo 及源码Option Base 1 Private comObj As CMCom '库中定义的类 Dim outZ As Variant '注意 Variant 数据类型Dim inX(5) As DoubleDim inY(5) As Double Private Sub Command1_Click() '生成样本: 三次多项式 + 小扰动 For i = 1 To 5 inX(i) = i inY(i) = i + 2 * i ^ 2 + 3 * i ^ 3 + 0.001 * Rnd(Now) Next i '调用 COM 组件成员函数 Call comObj.matlabPolyfit(1, outZ, inX, inY, 3) '输出赝本数据 txtMsg.Text = txtMsg.Text & vbCrLf & '> 样本如下:' & vbCrLf & vbCrLf txtMsg.Text = txtMsg.Text & ' ' & 'x y' & vbCrLf For i = 1 To 5 txtMsg.Text = txtMsg.Text & ' ' & inX(i) & ', ' & inY(i) & vbCrLf Next i '输出拟合多项式 txtMsg.Text = txtMsg.Text & vbCrLf & '> 输出拟合系数:' & vbCrLf & vbCrLf & ' Y = ' For i = 1 To 4 If i <> 4 Then txtMsg.Text = txtMsg.Text & Format(outZ(1, i), '0.000') & ' * X^' & (4 - i) & ' + ' Else txtMsg.Text = txtMsg.Text & Format(outZ(1, i), '0.000') & ' * X^' & (4 - i) End If Next i End Sub Private Sub Form_Load() Set comObj = New CMComEnd Sub Private Sub Form_Unload(Cancel As Integer) Set comObj = NothingEnd Sub
发布COM组件到其他计算机上时,目标计算机的环境需要有VC运行库msvcrt100.dll
如果目标计算机上装有MCR, 那打包COM组件时就不用添加MCR了