Matlab as a COM Server
Using FRED’s COM interface it is possible to exchange data with external programs such as MATLAB and Excel. This article presents an example where FRED and MATLAB are used respectively as the automation client and server in order to exchange data and create plots (i.e. Matlab is servicing requests being sent from FRED). There are a few steps that should be taken both in FRED and MATLAB before executing your script:
- Start an instance of MATLAB
- Execute the command: enableservice(‘AutomationServer’,true)
- Execute the command: enableservice(‘AutomationServer’)
- Right mouse click in the script editor and choose: Edit > References
- Choose the Matlab Type Library
- Dimension your Matlab object in the script as type MLApp.MLApp
The above steps will ensure that 1) FRED uses the current instance of MATLAB as the server instead of the command console, and 2) FRED loads the Matlab type library and can recognize and execute the server’s application commands.
Note that loading the Matlab type library is not required for a working COM connection between Matlab and FRED, though it does help facilitate scripting within the editor by providing syntax tooltips. The example file included in this KB article does not use the Matlab Type Library, instead defining the Matlab application object generically using: Set Matlab = CreateObject("Matlab.Application").
The example embedded script in the sample file with this article demonstrates how to use some of the following Matlab application commands:
- PutWorkspaceData: send real-valued data to Matlab
- PutFullMatrix: send complex-valued data to Matlab
- GetWorkspaceData: retrieve data from Matlab
- Execute: issue Matlab commands to the server for execution
Example file: fredToMatlab.frd