Using the MATLAB Runtime User Data Interface

The MATLAB® Runtime User Data Interface lets you easily access MATLAB Runtime data. It allows keys and values to be passed between a MATLAB Runtime instance, the MATLAB code running on the MATLAB Runtime, and the host application that created the instance. Through calls to the MATLAB Runtime User Data Interface API, you access MATLAB Runtime data by creating a per-instance associative array of mxArrays, consisting of a mapping from string keys to mxArray values. Reasons for doing this include, but are not limited to the following:

  • You need to supply run-time profile information to a client running an application created with the Parallel Computing Toolbox™. You supply and change profile information on a per-execution basis. For example, two instances of the same application may run simultaneously with different profiles. See Use Parallel Computing Toolbox in Deployed Applications for more information.

  • You want to set up a global workspace, a global variable or variables that MATLAB and your client can access.

  • You want to store the state of any variable or group of variables.

The API consists of:

  • Two MATLAB functions callable from within deployed application MATLAB code

  • Four external C functions callable from within deployed application wrapper code

MATLAB Functions

Use the MATLAB functions getmcruserdata and setmcruserdata from deployed MATLAB applications. They are loaded by default only in applications created with the MATLAB Compiler™ or MATLAB Compiler SDK™ products.

Tip

getmcruserdata and setmcruserdata will produce an Unknown function error when called in MATLAB if the MCLMCR module cannot be located. This can be avoided by calling isdeployed before calling getmcruserdata and setmcruserdata. For more information about the isdeployed function, see the isdeployed reference page.

Set and Retrieve MATLAB Runtime Data for Shared Libraries

There are many possible scenarios for working with MATLAB Runtime data. The most general scenario involves setting the MATLAB Runtime with specific data for later retrieval, as follows:

  1. In your code, include the MATLAB Runtime header file and the library header generated by MATLAB Compiler SDK.

  2. Properly initialize your application using mclInitializeApplication.

  3. After creating your input data, write or “set” it to the MATLAB Runtime with setmcruserdata .

  4. After calling functions or performing other processing, retrieve the new MATLAB Runtime data with getmcruserdata.

  5. Free up storage memory in work areas by disposing of unneeded arrays with mxDestroyArray.

  6. Shut down your application properly with mclTerminateApplication.

Was this topic helpful?