Main Content

Execute Deployed MATLAB Functions

This example shows how to use MATLAB® Client for MATLAB Production Server™ to invoke a MATLAB function deployed on a MATLAB Production Server instance.

MATLAB Client for MATLAB Production Server uses MATLAB Production Server add-ons to communicate between a MATLAB client and a server instance. A MATLAB Production Server add-on makes the functions in an archive deployed on MATLAB Production Server available in MATLAB. A deployed archive and its corresponding MATLAB Production Server add-on have the same name.

Installing the MATLAB Production Server add-on in your MATLAB desktop environment allows you to use the functions from a deployed archive in MATLAB. Installing a MATLAB Production Server add-on creates proxy functions of the deployed functions locally. The proxy functions manage communication between the deployed MATLAB functions and the clients that invoke the deployed functions. A proxy function and its corresponding deployed function have the same name. Since the proxy functions are MATLAB functions, you can call them from the MATLAB command prompt, other functions, or scripts. You can also compile the functions and scripts that contain the proxy functions. You can install MATLAB Production Server add-ons using the prodserver.addon.install function at the MATLAB command prompt or using the MATLAB Production Server Add-On Explorer app.

Calling the proxy MATLAB function sends an HTTP request across the network to an active MATLAB Production Server instance. The server instance calls the MATLAB function in the deployable archive and passes to it the inputs from the HTTP request. The return value of the deployed MATLAB function follows the same path over the network in reverse.

The following example describes how to install MATLAB Production Server add-ons and execute a deployed MATLAB function.

Install MATLAB Client for MATLAB Production Server

Install the MATLAB Client for MATLAB Production Server support package to your MATLAB desktop environment using the MATLAB Add-On Explorer. For information about installing add-ons, see Get and Manage Add-Ons (MATLAB).

Deploy MATLAB Function on Server

Write a MATLAB function mymagic that uses the magic (MATLAB) function to create a magic square. Package this function in an archive named mathfun, then deploy it on a running MATLAB Production Server instance.

You must include a MATLAB function signature file when you create the archive. You must enable the discovery service on the server instance that hosts the archive. For information on how to create and deploy the archive, see Create a Deployable Archive for MATLAB Production Server and Share the Deployable Archive.

function m = mymagic(in)
  m = magic(in);
end

Install MATLAB Production Server Add-On for the Deployable Archive

From your MATLAB desktop environment, install the MATLAB Production Server add-on for the deployed archive using the MATLAB Production Server Add-On Explorer app. Installing the add-on makes the MATLAB functions deployed on the server available to your MATLAB client programs. The MATLAB Production Server Add-On Explorer app is different from MATLAB Add-On Explorer.

Launch MATLAB Production Server Add-On Explorer App

From a MATLAB command prompt, launch the MATLAB Production Server Add-On Explorer app using the command prodserver.addon.Explorer.

>> prodserver.addon.Explorer

MATLAB Production Server Add-On Explorer

Add Server Information

In the MATLAB Production Server Add-On Explorer app, add information about the server that hosts the deployable archive mathfun.

  1. In the Servers section, click New.

  2. Enter the host name of the server in the Host box and the port number in the Port box. For example, for a server running on your local machine on port 9910, enter localhost for Host and 9910 for Port.

  3. Click OK to add the server.

  4. After you add the server, you can click Check Status to check the server status.

You can add multiple servers.

Add new server

Install Add-On

After you add a server, the Servers and Add-Ons section lists the server and the MATLAB Production Server add-ons that can communicate with the server. If you add multiple servers, this sections lists all the servers and the add-ons that can communicate with each server grouped under the server that hosts them.

Install the mathfun add-on to make the MATLAB function mymagic from the deployable archive mathfun available in your MATLAB client programs.

  1. Select the mathfun add-on.

  2. In the Add-Ons section, click Install. This installs the add-on.

Install add-on from MATLAB Production Server Add-On Explorer

Manage Installed Add-On

After you install a MATLAB Production Server add-on, the MATLAB Add-On Manager lists it. You can perform tasks such as enabling, disabling and uninstalling the add-on, and viewing details about the add-on. Viewing the add-on in Add-On Explorer is not supported.

Screen shot of Add-On Manager listing the mathfun add-on.

Invoke Deployed MATLAB Functions

Installing an add-on creates proxy MATLAB functions locally that let you invoke MATLAB functions deployed on the server. You can call the proxy functions from other MATLAB functions, scripts, or standalone applications. You can also call the proxy functions interactively from the MATLAB command prompt. For example, to invoke the mymagic function hosted on the server, you can call the proxy mymagic function from the MATLAB command prompt.

>> mymagic(3)

This prints a 3 by 3 magic square.

You can find more examples in the support_package_root\toolbox\mps\matlabclient\demo folder, where support_package_root is the root folder of support packages on your system. You can access the documentation by entering the doc command at the MATLAB command prompt or clicking the Help button in MATLAB desktop. In the Help browser that opens, navigate to MATLAB Client for MATLAB Production Server under Supplemental Software.

Related Topics