Using MATLAB Runtime User Data Interface - MATLAB & Simulink (original) (raw)
Main Content
The MATLAB® Runtime User Data Interface lets you easily access MATLAB Runtime data. This feature allows keys and values to be shared between a MATLAB Runtime instance, the MATLAB code running on that MATLAB Runtime instance, and the wrapper code that created the MATLAB Runtime instance. Through calls to the MATLAB Runtime User Data interface API, you access MATLAB Runtime data by creating a per-instance associative array ofmxArray
s, consisting of a mapping from string keys tomxArray
values. Reasons for doing this include, but are not limited to:
- You need to supply MATLAB Runtime 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. For more information, see Use Parallel Computing Toolbox in Deployed Applications.
- You want to initialize MATLAB Runtime with constant values that can be accessed by all your MATLAB applications.
- 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.
MATLAB Functions
The API consists of two MATLAB functions callable from within deployed MATLAB code. Use the MATLAB functions getmcruserdata and setmcruserdata from deployed MATLAB applications. They are loaded by default only in applications created withMATLAB Compiler™ or MATLAB Compiler SDK™.
Tip
getmcruserdata
and setmcruserdata
produce an Unknown function
error when called in MATLAB if the MCLMCR module cannot be located. You can avoid this situation by calling isdeployed
before calling getmcruserdata andsetmcruserdata. For more information, see isdeployed.
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:
- In your code, include the MATLAB Runtime header file and the library header generated by MATLAB Compiler SDK.
- Properly initialize your application using
mclInitializeApplication
. - After creating your input data, write or set it to theMATLAB Runtime with setmcruserdata.
- After calling functions or performing other processing, retrieve the newMATLAB Runtime data with getmcruserdata.
- Free up storage memory in work areas by disposing of unneeded arrays with
mxDestroyArray
. - Shut down your application properly with
mclTerminateApplication
.
See Also
setmcruserdata | getmcruserdata
Topics
- Use Parallel Computing Toolbox in Deployed Applications
- Specify Parallel Computing Toolbox Profile in .NET Application (MATLAB Compiler SDK)
- Specify Parallel Computing Toolbox Profile in Java Application (MATLAB Compiler SDK)