Borrar filtros
Borrar filtros

Error in MATLAB COM Automation

1 visualización (últimos 30 días)
Elvin
Elvin el 30 de En. de 2014
Comentada: Elvin el 30 de En. de 2014
Anyone knows how to do MATLAB COM autiomation in VB.NET? Since I really can't make my program works using the NE builder. I tried using the COM automation as documented here: http://www.mathworks.com/help/matlab/matlab_external/call-a-matlab-function-from-visual-basic-net-client.html
Again, my program is so simple. Here's the matlab code:
function out = addMe(a,b)
out = a + b;
end
Here's the VB code:
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
The result that I'm getting that is showing in the textbox is: ? ?? Undefined function or variable 'a' . I already made sure that the COM reference is already added.
But when I tried changing the code to this it is working.
result = Matlab.Execute("version")
I hope you can help me with this. I really needed this. Thanks

Respuesta aceptada

Walter Roberson
Walter Roberson el 30 de En. de 2014
You need to put the value from the VB space into the MATLAB space. See the example http://www.mathworks.com/help/matlab/ref/putworkspacedata.html
  1 comentario
Elvin
Elvin el 30 de En. de 2014
I changed my code to this but I'm getting an error:
Public Class Form1
Dim Matlab As Object
Dim a As Integer = 4
Dim b As Integer = 10
Dim result As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Matlab = CreateObject("Matlab.Application")
Matlab.PutWorkspaceData("a", "base", a)
Matlab.PutWorkspaceData("b", "base", b)
Matlab.Execute("cd C:\Users\Elvin Gentiles\Desktop\Program")
result = Matlab.Execute("out = addMe(a,b)")
result = Matlab.GetVariable("out", "base")
TextBox1.Text = result
End Sub
End Class
Here's the error

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Write COM Applications to Work with MATLAB en Help Center y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by