Working Between the MathWorks, Inc. MATLAB® Software Development Environment and LabVIEW

Updated Aug 24, 2023

Reported In

Software

  • LabVIEW Full
  • LabVIEW Professional
  • LabVIEW MathScript Module

Issue Details

I have scripts written in the MATLAB® software. What are my options for sharing data between LabVIEW and The MathWorks, Inc. MATLAB® software environment?

Solution

There are several options for importing/exporting data from the MATLAB® environment and LabVIEW.
 

The MATLAB® Script Node in LabVIEW

The MATLAB® Script Node is a structure that is included with LabVIEW Full Development System for Windows as of LabVIEW 5.1. It can be found on the Scripts & Formula VIs palette. The MATLAB® Script Node makes ActiveX calls to MATLAB® software from within LabVIEW. This requires that a valid license of MATLAB® be installed on the same machine as LabVIEW. Follow these step for using the MATLAB® script node.

With the MATLAB® script node you can run the MATLAB® software programmatically from a LabVIEW program.  You may enter the MATLAB® script in the node or import pre-existing MATLAB® code into the node.
 

MATLAB® Data Plugin

The MATLAB® Data Plugin allows you to import and export level 4 and 5 MATLAB® files, and directly read *.MAT files.  As such, this is a great option for utilizing existing *.MAT data sets in LabVIEW, or creating data sets within LabVIEW that can then be utilized within MATLAB® software.
 

Data Transfer Options

NI has an example program  that allows a user to read LabVIEW generated TDM/TDMS files within The MathWorks, Inc. MATLAB® software. This example uses a TDM C DLL and an adapted C-header file that can be used in conjunction with MATLAB®. 

For all versions of LabVIEW, data transfer between the two environments can be performed by saving the data in a file using the MATLAB® software and reading it directly from LabVIEW, or vice versa. In the MATLAB® environment, the Save command allows you to save data in binary (*.mat) or ASCII format. On the reverse side, the Load command allows you to read the data back into the program. 


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

Additional Information

Incorporating Data Transfer Options

To save a vector or a matrix X in ASCII format with tab delimiter, enter the following in the command window or m-script file in the MATLAB® environment:
>>SAVE filename X -ascii -double -tabs
This creates a file whose name is filename and contains the data X in ASCII format with a tab delimiter. Import the file into LabVIEW using the Read From Spreadsheet File VI  located on the Programming»File I/O palette. 

To load data, enter the following in the command window of the MATLAB® environment, or in the m-script file:
>>LOAD filename