Methods for Working with DIAdem and MATLAB®: Data Transfer and Interprogram Communication

Updated Oct 15, 2018

Reported In


  • DIAdem

Issue Details

How can I use DIAdem to invoke the MATLAB script server to run scripts written in The MathWorks, Inc. MATLAB® language syntax?  Also, how can I transfer data back and forth between DIAdem and the MATLAB environment?


Using DIAdem to invoke the MATLAB script server to run MScripts and push data back and forth between the MATLAB environment and DIAdem:
  1. Detach ScriptLibrary.OCX in to the DIAdem directory and register it through regsrv32, either by pressing “Windows R” or “Start\Run” to bring up the run menu. At the Run prompt type (Please replace the complete file path of ScriptLibrary.OCX with the file path in the prompt type bellow):

    For Windows 2000 & NT
    c:\winnt\system32\regsvr32 "diadem\ScriptLibrary.ocx"

    For Windows XP
    c:\Windows\system32\regsvr32 "diadem\ScriptLibrary.ocx"

    For Windows 7 and Windows 10
    regsvr32 "diadem\ScriptLibrary.ocx"

    This will register the ScriptLibrary.ocx on your computer. 
  2. Next, Copy the attached file, FFTTest1.M into the "Current directory" folder as specified in the MATLAB software. To determine the current directory folder, start the MATLAB software, and from the file menu select, "Set Path". 
  3. Finally detach and run the script MatLabTest1.VBS from within DIAdem. 

    The script does the following
  1. Generates data in DIAdem.
  2. Diadem transfers the data to the MATLAB software.
  3. DIAdem invokes the MATLAB script server to run an Mscript (FFTTest1.M) that performs an FFT on the data transferred from DIAdem. 
  4. The MATLAB software then returns the results to DIAdem.
  5. DIAdem then pauses for 5 seconds showing the results returned from the MATLAB software.
  6. Then DIAdem calculates an FFT and displays both the MATLAB software results and DIAdem FFT results in VIEW.
DIAdem is calling the MATLAB software through it’s ActiveX interface, the ScriptLibrary.ocx is managing data type conversions between the MATLAB software and DIAdem’s VBScript engine as well as the object instantiation.

The attached example “MatLabTest1.VBS” contains all the code that opens a connection between the MATLAB environment and DIAdem, allowing for transfer of data and running of Mscripts

The following lines from the VBS script referred to in the previous paragraph create the interface:
Dim oMatLabM 'Create MatLAB Object variable
Set oMatLabM = CreateObject("DIAdem.ScriptLibrary.MATLAB")

The object variable “oMatLabM” now can be used in the DIAdem script to access the complete ActiveX interface of the MATLAB environment.

To push a DIAdem data channel to the MATLAB software use the following syntax:
Call oMATLAB.PutChannel("Sine_Wave")
Where “Sine_Wave” is an existing channel in DIAdem data.

To pull an array back from the MATLAB software into the DIAdem data area, use the following syntax:
Call oMATLAB.GetChannel("FFTRes")
Where “FFTRes” is an array created in the MATLAB environment

To Run an Mscript, use the following syntax:
Call oMATLAB.Execute("FFTTest1")

The first time you run the script it my be necessary to have the MATLAB software open. If you get an error message, "Can not create Object, Out of Memory", just start the MATLAB software and run the script again. You should only have to do this the first time.

This tool is unsupported.

MATLAB® is a registered trademark of The MathWorks, Inc. Other product and company names listed are trademarks and trade names of their respective companies.



Not Helpful