| Contents | Index |
| On this page… |
|---|
Automation is a COM protocol that allows one application (the controller or client) to control objects exported by another application (the server). MATLAB software on Microsoft Windows operating systems supports COM Automation server capabilities. Any Windows program that can be configured as an Automation controller can control MATLAB. Some examples of applications that can be Automation controllers are Microsoft Excel, Microsoft Access, and Microsoft Project applications, and many Microsoft Visual Basic and Microsoft Visual C++ programs.
Note If you plan to build your client application using C/C++, or Fortran, we recommend you use MATLAB Engine instead of an Automation server. |
To create a server, you need a programmatic identifier (ProgID) to identify the server. The ProgID for MATLAB is matlab.application. For other MATLAB ProgIDs, see Programmatic Identifiers.
How you create an Automation server depends on the controller you are using. Consult your controller's documentation for this information.
If your controller is a MATLAB application and your server is another MATLAB application, you create the Automation server using the actxserver function:
h = actxserver('matlab.application')
h =
COM.matlab.applicationThis command automatically creates the Automation server. You can also create the server manually. See Creating the Server Manually.
The following topics:
The MATLAB Automation server has two modes:
Shared — One or more client applications connect to the same MATLAB server. All clients share the same server.
Dedicated — Each client application creates its own dedicated MATLAB server.
If you use matlab.application as your ProgID, MATLAB creates a shared server. For information about creating shared and dedicated servers, see Specifying a Shared or Dedicated Server.
The MATLAB Automation server starts up in the matlabroot\bin\win32 folder. If this is not the Startup Folder for the MATLAB Program, the newly created server does not run the MATLAB startup file (startup.m) and does not have access to files in that folder.
To access files in the startup folder, do one of the following:
Set the server's working folder to the startup folder (using the cd function) and add the startup folder to the server's MATLAB path (using the addpath function).
Include the path name to the startup folder when referencing those files.
Use the enableservice function to determine the current state of a MATLAB Automation server. The function returns a logical value, where logical 1 (true) means MATLAB is an Automation server and logical 0 (false) means MATLAB is not an Automation server.
For example, if you type:
enableservice('AutomationServer')
and MATLAB displays:
ans =
1then MATLAB is currently an Automation server.
If you use a Visual Basic client application to access a MATLAB Automation server, you have two options for creating the server:
Accessing Methods from the Visual Basic Object Browser. You can use the Object Browser of your Visual Basic client application to see what methods are available from a MATLAB Automation server. To do this you need to reference the MATLAB type library in your Visual Basic project.
To set up your Visual Basic project:
In your Visual Basic code, use the New method to create the server:
Matlab = New MLApp.MLApp
View MATLAB Automation methods from the Visual Basic Object Browser under the Library called MLAPP.
Using CreateObject. To use the Visual Basic CreateObject method, type:
MatLab = CreateObject("Matlab.Application")It is not always necessary to create a new instance of a MATLAB server whenever your application needs some task done in MATLAB. Clients can connect to an existing MATLAB Automation server using the actxGetRunningServer function or by using a command similar to the Visual Basic .NET GetObject command.
The Visual Basic .NET command shown here returns a handle h to the MATLAB server application:
h = GetObject(, "matlab.application")
Note It is important to use the syntax shown above to connect to an existing MATLAB Automation server. Omit the first argument, and make sure the second argument is as shown. |
The following Visual Basic .NET example connects to an existing MATLAB server, then executes a plot command in the server. If you do not already have a MATLAB server running, create one following the instructions in Creating a MATLAB Automation Server from Visual Basic .NET Application.
Dim h As Object
h = GetObject(, "matlab.application")
' Handle h should be valid now.
' Test it by calling Execute.
h.Execute ("plot([0 18], [7 23])")
![]() | MATLAB COM Automation Server Support | MATLAB Automation Server Functions and Properties | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2012- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |