LabVIEW MathScript RT Module

cancel
Showing results for 
Search instead for 
Did you mean: 

MathScript Nugget #18: Moving Data Around

As much as we would like to believe that our customers use MathScript and only MathScript, we understand that sometimes you use other programs too. Maybe you want to save some data to a spreadsheet so a colleague can look at it. Or maybe you use LabVIEW for data acquisition but you want to use MathScript for data analysis. Whatever the reason, you'll be happy to know that MathScript has solutions for moving your data to and from other languages and programs. This MathScript Nugget will explore some easy ways to transfer data between MathScript and the rest of LabVIEW. The next MathScript Nugget will cover ways to transfer between MathScript and other programs besides LabVIEW.

The simplest way to transfer data between MathScript and LabVIEW is with the inputs and outputs of the MathScript Node. These are ideal for things like passing acquired data to MathScript for analysis or passing the results of your algorithm back to LabVIEW for display on a front panel.

datainout.png

It is also very common to need to transfer data between the MathScript Node and MathScript Window. Perhaps you want to move some acquired data to the MathScript Window to play around with it or put some filter coefficients that you designed in the MathScript Window into your algorithm in a VI. There are several different ways to do this.

The simplest is copy and paste. You can right-click on a variable display in the MathScript Window (or Probe) and copy its data to a control or constant on a VI. You can copy an entire array or individual elements in this manner.

copy.png     paste.png

You can also copy textual data from the Output Window pane of the MathScript Window or the Output tab of the MathScript Probe. Then you can paste it into a script to take it across the chasm.

copy text.png    paste text.png

Finally, you can copy individual variables or entire workspaces between the MathScript Window and a MathScript Node using MathScript global variables or the load and save functions.

You can create global variables using the global function. You need to call this function from both the MathScript Window and the MathScript Node that you want to have access to the global variable. Once you do, any change to the variable in one place will be reflected in the other. Note that the two places must be running in the same application instance for global variables to work. Also, despite their similar names and purposes, MathScript global variables are not the same thing as LabVIEW global variables and they don't interact in any way.

You can use the save function to store every variable that exists in your workspace or to store individual variables. The variables are saved to a .MLV binary file on disk. You can then use the load function to recover those variables in another location or at another time. This is most commonly used to save a work session in the MathScript Window so that you can continue where you left off the next day, but it can also transfer data between the MathScript Window and a MathScript Node.

Unfortunately, the global, load, and save functions all cause the MathScript Node to have a warning glyph. This is because of the dynamic way that they can introduce variables of any name and datatype at run-time. One way to work around the performance limitations that this introduces is to call these functions in one MathScript node and pass the result to another MathScript Node. This way, the poor performance will only affect the node that calls the offending function, not your entire algorithm.

twonodes.png

jattas
LabVIEW MathScript R&D

ps. Check out more MathScript Nuggets!
Message 1 of 1
(6,459 Views)