Documentation Center

  • Trial Software
  • Product Updates

MATLAB Automation Server Functions and Properties

MATLAB® functions and properties enable an Automation controller to manipulate data in the MATLAB workspace. MATLAB can be both a controller and a server. The examples in this section use MATLAB as the client application.

This section explains how to call functions in the MATLAB Automation server and how to use properties that affect the server. These are shown in the following tables and are described in individual function reference pages.

Executing Commands in the MATLAB Server

The client program can execute commands in the MATLAB server using these functions.

FunctionDescription

Execute

Execute MATLAB command in server

Feval

Evaluate MATLAB command in server

Using Execute

Use the Execute function when you want the MATLAB server to execute a command that can be expressed in a single string. For example:

h = actxserver('matlab.application');

h.PutWorkspaceData('A', 'base', rand(6))
h.Execute('A(4:6,:) = [];'); % remove rows 4-6
B = h.GetWorkspaceData('A', 'base')

MATLAB displays:

B =
    0.6208    0.2344    0.6273    0.3716    0.7764    0.7036
    0.7313    0.5488    0.6991    0.4253    0.4893    0.4850
    0.1939    0.9316    0.3972    0.5947    0.1859    0.1146

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

Using Feval

Use the Feval function when you want the server to execute commands that you cannot express in a single string. The following example uses variables defined in the client, rows and cols, to modify the server.

This is a continuation of the previous example:

rows = 6;   cols = 3;
h.Feval('reshape', 0, 'A=', rows, cols);

MATLAB interprets A in the expression 'A=' as a server variable name.

The reshape function in the previous statement does not make an assignment to the server variable A; it is equivalent to the following MATLAB statement:

reshape(A,6,3)

which returns a result, but does not assign the new array. If you get the variable A from the server, it is unchanged:

B = h.GetWorkspaceData('A', 'base')

MATLAB displays:

B =
    0.6208    0.2344    0.6273    0.3716    0.7764    0.7036
    0.7313    0.5488    0.6991    0.4253    0.4893    0.4850
    0.1939    0.9316    0.3972    0.5947    0.1859    0.1146

Use the Feval function return value to get the result of this type of operation. For example, the following statement reshapes the server-side array A and returns the result of this operation in the client-side variable a:

a = h.Feval('reshape', 1, 'A=', rows, cols);

The Feval function returns a cell array. To view the contents, type:

a{:}

MATLAB displays:

ans =
    0.6208    0.6273    0.7764
    0.7313    0.6991    0.4893
    0.1939    0.3972    0.1859
    0.2344    0.3716    0.7036
    0.5488    0.4253    0.4850
    0.9316    0.5947    0.1146

Exchanging Data with the Server

MATLAB provides functions to read and write data to any workspace of a MATLAB server. In these commands, pass the name of the variable to read or write, and the name of the workspace holding that data.

FunctionDescription

GetCharArray

Get character array from server

GetFullMatrix

Get matrix from server

GetWorkspaceData

Get any type of data from server

PutCharArray

Store character array in server

PutFullMatrix

Store matrix in server

PutWorkspaceData

Store any type of data in server

The Get/PutCharArray functions read and write string values to the MATLAB server.

The Get/PutFullMatrix functions pass data as a SAFEARRAY data type. You can use these functions with any client that supports the SAFEARRAY type. This includes MATLAB and Visual Basic® clients.

The Get/PutWorkspaceData functions pass data as a variant data type. Use these functions with any client that supports the variant type. These functions are especially useful for VBScript clients because VBScript does not support the SAFEARRAY data type.

In this example, write a string to variable str in the base workspace of the MATLAB server and read it back to the client:

h = actxserver('matlab.application');
h.PutCharArray('str', 'base', ...
   'He jests at scars that never felt a wound.');

S = h.GetCharArray('str', 'base')
S =
  He jests at scars that never felt a wound.

Controlling the Server Window

These functions enable you to make the server window visible or to minimize it.

FunctionDescription

MaximizeCommandWindow

Display server window on Windows® desktop

MinimizeCommandWindow

Minimize size of server window

In this example, create a COM server running MATLAB and minimize it:

h = actxserver('matlab.application');
h.MinimizeCommandWindow;

Terminating the Server Process

When you are finished with the MATLAB server, quit the MATLAB session.

FunctionDescription

Quit

Quit the MATLAB session

To quit MATLAB, type:

h.Quit;

To release the MATLAB object, type:

clear h

Client-Specific Information

This section provides information specific to MATLAB and Visual Basic .NET clients only.

For MATLAB Clients

To see a summary of all functions along with the required syntax, use the invoke function as follows:

handle = actxserver('matlab.application');
handle.invoke

For Visual Basic .NET Clients

Data types for the arguments and return values of the server functions are expressed as Automation data types, which are language-independent types defined by the Automation protocol.

For example, BSTR is a wide-character string type defined as an Automation type, and is the same data format used by the Visual Basic language to store strings. Any COM-compliant controller should support these data types, although the details of how you declare and manipulate these are controller specific.

Using the Visible Property

You have the option of making MATLAB visible or not by setting the Visible property. When visible, MATLAB appears on the desktop, enabling the user to interact with it. This might be useful for such purposes as debugging. When not visible, the MATLAB window does not appear, thus perhaps making for a cleaner interface and also preventing any interaction with the application.

By default, the Visible property is enabled, or set to 1:

h = actxserver('matlab.application');
h.Visible
ans =
     1

You can change the Visible property by setting it to 0 (invisible) or 1 (visible). The following command removes the server application window from the desktop:

h.Visible = 0;
h.Visible
ans =
     0
Was this topic helpful?