Vb.net matlabcom自动化中的错误
有人知道如何在VB.NET中进行MATLAB COM编程吗?因为我真的无法使用NE builder使我的程序工作。我尝试使用COM自动化,如下所述: 同样,我的程序很简单。以下是matlab代码:Vb.net matlabcom自动化中的错误,vb.net,matlab,com,automation,com-automation,Vb.net,Matlab,Com,Automation,Com Automation,有人知道如何在VB.NET中进行MATLAB COM编程吗?因为我真的无法使用NE builder使我的程序工作。我尝试使用COM自动化,如下所述: 同样,我的程序很简单。以下是matlab代码: function out = addMe(a,b) out = a + b; end 下面是VB代码: Public Class Form1 Dim a As Integer = 4 Dim b As Integer = 10 Dim result As String
function out = addMe(a,b)
out = a + b;
end
下面是VB代码:
Public Class Form1
Dim a As Integer = 4
Dim b As Integer = 10
Dim result As String
Dim Matlab As Object
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Matlab = CreateObject("Matlab.Application")
result = Matlab.Execute("cd C:\Users\Elvin Gentiles\Desktop\Program")
result = Matlab.Execute("addMe(a,b)")
TextBox1.Text = result
End Sub
End Class
文本框中显示的结果是:???未定义的函数或变量“a”。我已确保已添加COM引用
但当我尝试将代码更改为此时,它正在工作。顺便说一下,version是一个用于显示matlab版本的matlab命令
result = Matlab.Execute("version")
我希望你能帮我做这件事。我真的需要这个。谢谢你,一切都很好 问问自己:您希望函数返回什么 如果上面的代码是完整的,那么您在matlab会话中既没有定义
a
也没有定义b
,因此matlab当然会抱怨没有定义a
试一试
相反。如果我想将变量的值从VB传递到MATLAB,该怎么办?顺便说一句,我试过你的建议,得到的答案是???“double”类型输入参数的未定义函数“addMe”。您以前使用过Matlab吗?这个错误消息是不言自明的。您必须确保
addMe
函数位于路径上-我有点假设addMe.m
将位于cd
要访问的目录中。您可以执行Matlab.Execute(“a=2”)等操作,或者检查(PutFullMatrix
,PutWorkspaceData
)两个矩阵如何更直接地写入Matlab。
result = Matlab.Execute("addMe(1,2)")