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

Execute MATLAB command in Automation server

Synopsis

IDL Method Signature

BSTR Execute([in] BSTR command)

Microsoft Visual Basic Client

Execute(command As String) As String

MATLAB Client

result = Execute(h,'command')

Description

The Execute function executes the MATLAB® statement specified by command in the MATLAB Automation server attached to h. To call a function with arguments, use Feval.

The server returns output from the command and any MATLAB warning or error messages in result. 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.

Examples

collapse all

This example shows how to execute a command on a MATLAB matrix and return the result to the Visual Basic® .NET client. The example creates a matrix in the client and modifies the contents in the MATLAB workspace.

type comexecute.vb
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))

This example shows how to execute a command on a MATLAB matrix and return the result to the VBA client. The example creates a matrix in the client and modifies the contents in the MATLAB workspace.

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

Tips

  • 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.

Introduced before R2006a