This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Execute MATLAB command in Automation server


IDL Method Signature

BSTR Execute([in] BSTR command)

Microsoft Visual Basic Client

Execute(command As String) As String


result = Execute(h,'command')


The Execute function executes the MATLAB® statement specified by command in the MATLAB Automation server attached to handle h.

The server returns output from the command in result. result also contains any MATLAB warning or error messages.

If you terminate the MATLAB command with a semicolon and there are no warnings or error messages, result might be empty.

COM functions are available on Microsoft® Windows® systems only.

Visual Basic .NET Examples

Create a 6-by-6 matrix in the MATLAB server, remove rows 4–6, and return the results to the client. To run examples in products that execute VBA code, see Tips.

Dim Matlab As Object 
Dim data(6) As Double 
Dim B As Object 
B = Nothing 
Matlab = CreateObject("matlab.application") 
For i = 0 To 6 
    data(i) = i * 15 
Next i 
Matlab.PutWorkspaceData("A", "base", data) 
Matlab.Execute("A = A.*2;") 
Matlab.GetWorkspaceData("A", "base", B) 
MsgBox("Doubled second value of A = " & B(0, 1))


  • To display output from Execute in the client window, specify an output variable, result.

  • If there is an error, the Execute function returns the MATLAB error message with the characters ??? prepended to the text.

  • To run examples in Microsoft Office products that execute VBA code, replace the statement:

    MatLab = CreateObject("matlab.application")


    Set MatLab = CreateObject("matlab.application")

    If you need more information, then refer to your VBA product documentation.

Introduced before R2006a