马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有账号?我要加入
x
最近小弟做起了VB与matlab混编
matlab下源文件:
function ff(x,y,z)
mesh(x,y,z);
hold on
成功做成COM控件后(名称为vv的控件),VB调用:
全代码如下:
Private factor As vv.vv
Private Sub Command1_Click()
On Error GoTo handle_error
Dim x(15) As Variant
Dim y(15) As Variant
Dim z(15) As Variant
Dim k As Double
Dim p(5, 5, 3) As Double
Dim factor As vv.vv
p(0, 0, 0) = 12: p(0, 0, 1) = 145: p(0, 0, 2) = 50 '输入16个点数据
p(0, 1, 0) = 24: p(0, 1, 1) = 120: p(0, 1, 2) = 50
p(0, 2, 0) = 45: p(0, 2, 1) = 117: p(0, 2, 2) = 50
p(0, 3, 0) = 65: p(0, 3, 1) = 140: p(0, 3, 2) = 50
p(1, 0, 0) = 24: p(1, 0, 1) = 65: p(1, 0, 2) = 34
p(1, 1, 0) = 56: p(1, 1, 1) = 45: p(1, 1, 2) = 34
p(1, 2, 0) = 87: p(1, 2, 1) = 56: p(1, 2, 2) = 34
p(1, 3, 0) = 99: p(1, 3, 1) = 75: p(1, 3, 2) = 34
p(2, 0, 0) = 43: p(2, 0, 1) = 120: p(2, 0, 2) = 20
p(2, 1, 0) = 65: p(2, 1, 1) = 98: p(2, 1, 2) = 20
p(2, 2, 0) = 87: p(2, 2, 1) = 100: p(2, 2, 2) = 20
p(2, 3, 0) = 111: p(2, 3, 1) = 115: p(2, 3, 2) = 20
p(3, 0, 0) = 15: p(3, 0, 1) = 165: p(3, 0, 2) = 0
p(3, 1, 0) = 34: p(3, 1, 1) = 120: p(3, 1, 2) = 0
p(3, 2, 0) = 55: p(3, 2, 1) = 135: p(3, 2, 2) = 0
p(3, 3, 0) = 75: p(3, 3, 1) = 170: p(3, 3, 2) = 0
Set factor = New vv.vv
k = -1
For i = 0 To 3
For j = 0 To 3
k = k + 1
x(k) = p(i, j, 0)
y(k) = p(i, j, 1)
z(k) = p(i, j, 2)
Next j
Next i
Call factor.ff(x, y, z)
handle_error:
MsgBox (Err.Description)
End Sub
结果运行后告诉我:
Z must be a matrix,not a scalar or vector.
但是要是把MATLAB 的源文件 中mesh 变成 plot3(x,y,z)就能正常运行,如图
|