Main Content

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

result = Execute(h,'command') 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

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

Version History

Introduced before R2006a