Apama 10.3 | Apama Documentation | Developing Apama Applications | Developing Apama Applications in EPL | Using EPL Plug-ins | Using MATLAB® products in an application
Using MATLAB® products in an application
MatlabManager actions
MATLAB examples
To use MATLAB analysis and modeling capability in an Apama application or in an application built using Apama Capital Markets Foundation, you need to add the MATLAB EPL bundle to your project (see Adding EPL bundles to projects) and ensure that the MATLAB executables and libraries are available to the correlator. The MATLAB bundle provides access to the MATLAB analysis and modeling toolkit from Apama EPL code and includes an EPL plug-in.
For information about the supported MATLAB versions, see the Supported Platforms document for the current Apama version. This is available from the following web page: http://documentation.softwareag.com/apama/index.htm.
This MATLAB plug-in lets you connect to and use the MATLAB engine. However, there are some functions/toolkits for which MATLAB does not support integration with C or Fortran on some operating platforms. Check the MATLAB documentation before using the MATLAB EPL plug-in.
The recommended way to use the MATLAB plug-in is to use the MatlabManager event, and call the relevant action and supply a callback. The call goes directly to the MATLAB plug-in, so you do not need to route a request event. *Response events are routed from the MATLAB plug-in to the calling context. Each request action automatically sets up a listener for the *Response event that will call the supplied callback. You can supply the relevant doesNothing*Callback() action from the MatlabManager event if you are not interested in the results of the callback. If you use the MatlabManager actions, you do not need to call the #initialize() action.
The legacy way to use the MATLAB plug-in is to route *Request events and set up listeners for the *Response events. If you are using the MATLAB plug-in in only the main context, injecting MatlabService.mon sets up all required listeners for the *Request events that call into the MATLAB plug-in. To use the MATLAB plug-in from another context, instantiate a MatlabManager variable, spawn to the other context, and call #initialize() on the variable. This sets up the required listeners in the current (non-main) context, and the *Response events are routed to this context.
Note: The MATLAB plug-in is asynchronous (except for the OpenSession requests), so the processing of the input queue, or calling the request actions, does not block.
Due to a shutdown timing issue in MATLAB, if you repeatedly open and close MATLAB sessions, you may see the error Error message - A primary message table for module 77. This is due to a race with shutting down the MATLAB COM server. The workaround for this is to have an unused idle MATLAB instance running that will keep the COM server running.
The MATLAB plug-in is multi-context aware. The *Response events are routed to the calling context.
* To include MATLAB capabilities in your application
1. Ensure that the directory containing the MATLAB plug-in library is included in the library search path: %APAMA_HOME%\bin should be in the PATH on Windows platforms. Or for deployment on Linux operating systems, $APAMA_HOME/lib should be in the LD_LIBRARY_PATH.
2. Import the MATLAB plug-in in the application's EPL code.
3. Set the appropriate values for your PATH environment variable:
*64-bit Windows: Add MATLAB_HOME/bin and MATLAB_HOME/bin/win64 to %PATH%.
*64-bit Linux: Add MATLAB_HOME/bin to $PATH. Also, add MATLAB_HOME/sys/os/glnxa64 and MATLAB_HOME/bin/glnxa64 to the end of $LD_LIBRARY_PATH (after the Apama library).
Note: On Linux, if you have problems starting Apama and MATLAB, especially with library incompatibilities such as with libssl, libcryto or libz, ensure the LD_LIBRARY_PATH is ordered to load the newest version of the library first (which may be in the Apama or MATLAB installation, or the version in the operating system). It may help to try running a standalone MATLAB from an Apama Command Prompt, or to use the ldd utility to diagnose.

Copyright © 2013-2018 | Software AG, Darmstadt, Germany and/or Software AG USA, Inc., Reston, VA, USA, and/or its subsidiaries and/or its affiliates and/or their licensors.