dgxw82544514 发表于 2009-3-31 15:10

mesh不能做VB的com控件么?(全代码)

最近小弟做起了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)就能正常运行,如图

ChaChing 发表于 2009-3-31 16:15

help mesh

dgxw82544514 发表于 2009-3-31 16:35

回复chaching

chanching:
您好
既然plot3(x,y,z),运行正确,说明Z是矩阵形式,不是矢量啊

ydlcsu 发表于 2009-3-31 17:12

回复 板凳 dgxw82544514 的帖子

既然plot3(x,y,z),运行正确,说明Z是矩阵形式,不是矢量啊

晕。。看样子你还没搞清楚矩阵和矢量的区别。。另外,再去仔细比较下mesh和plot3对输入参数的要求吧

[ 本帖最后由 ydlcsu 于 2009-3-31 17:18 编辑 ]

dgxw82544514 发表于 2009-3-31 17:22

回复 ydlcsu

ydlcsu:
你好
谢谢您的解释,我明白了,已经修改过来,运行正常。
       (mesh 输入的必须为矩阵)
          再次谢谢chanching和ydlcsu:handshake
页: [1]
查看完整版本: mesh不能做VB的com控件么?(全代码)