In
MathScript Nugget #18, we looked at ways to transfer data between MathSript and the rest of LabVIEW. In today's nugget, we'll see some of the different ways that MathScript can share data with programs besides LabVIEW.
The most common way to share data between programs is by reading and writing files. MathScript supports several file formats that are recognized by other programs. The ones we'll touch on in this nugget are MLV, MAT, CSV, TXT, TDM(S) and XLS.
The easiest way to bring data into MathScript is with the 'load' function. The
help topic for this function does a great job of explaining it. The load function will bring in a group of variables that have been saved to a file earlier. The most common formats that load supports are:
- MLV files created with MathScript save function
- MAT files created with version 6.0 or earlier of The MathWorks, Inc. MATLAB® software
- TDM and TDMS binary measurement files created in LabVIEW or DIAdem
The load and save functions are great for storing off a group of variables to be used again in a future session of MathScript. You can do the same thing using the Operate>>Load Data... and Operate>>Save Data... menu items in the MathScript Window. These support the same file formats as load and save.
The best formats to use if you want to share data with other applications are TXT, CSV, and XLS. MathScript has special funcitons to read and write each of these formats. The functions, such as
fread_csv and
fwrite_xls, are all members of the
support class.
The last way to read and write data files with MathScript is to use a custom file format. MathScript supports common file operations like
fread and
fwrite. You can use these functions to create or import files of any binary or textual format.
There's one last way to move data out of MathScript without using files. You can copy data from the MathScript Window or MathScript Probe as tab-delimited text to your OS clipboard. You can then paste this text to a text editor or spreadsheet program.

Hopefully now you have an idea of the many ways to move data into and out of MathScript.
MATLAB® is a registered trademark of The MathWorks, Inc.
jattas
LabVIEW MathScript R&D
ps Check out
more MathScript Nuggets!