Main Content

Call MATLAB Function from Visual Basic .NET Client

R2026b

Note

To call a MATLAB® function from a Microsoft® Visual Basic® .NET application in MATLAB R2022b or later, consider using the MATLAB Engine API for .NET. For more information, see Call MATLAB from .NET. For examples, see MathWorks.MATLAB.Engine.MATLABEngine.

If you need to maintain existing programs created for MATLAB R2022a or earlier, use this example which calls MATLAB functions from a Visual Basic .NET client application through a COM interface. The example plots a graph in a new MATLAB window and performs a simple computation.

Dim MatLab As Object
Dim Result As String
Dim MReal(1, 3) As Double
Dim MImag(1, 3) As Double

MatLab = CreateObject("Matlab.Application")

'Call MATLAB function from VB
Result = MatLab.Execute("surf(peaks)")

'Execute simple computation
Result = MatLab.Execute("a = [1 2 3 4; 5 6 7 8]")
Result = MatLab.Execute("b = a + a ")

'Bring matrix b into VB program
MatLab.GetFullMatrix("b", "base", MReal, MImag)

See Also

| |

Topics