Reputation: 33
I've written a Matlab script which it calls several functions within itself, and now I need to run it from VB.net. The Matlab script has no input from VB, but it has an image output and a number from the workspace. After watching this youtube video, and reading this page, I wrote the following code within VB.net: (In this code main.m is the name of Matlab script)
Public Class Form1
Dim MatLab As Object
Dim Result As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
MatLab = CreateObject("Matlab.Application")
Result = MatLab.Execute("cd D:\\main.m\")
End Sub
End Class
Also, I tried to use these pages (link 1, link 2), but they returned errors.
Upvotes: 0
Views: 253
Reputation: 18320
cd
stands for Change Directory. If you call cd D:\main.m\
you're trying to navigate to a directory called main.m
(which does not exist).
You have to do this in two steps: Change the directory first, then execute the file.
'Change directory to "D:\".
Result = MatLab.Execute("cd D:\")
'Execute "main.m".
Result = MatLab.Execute("main")
Upvotes: 2