Using LabVIEW MathScript RT Module


This article discusses what the LabVIEW MathScript RT Module is, and it gives an overview to the two methods of interacting with the MathScript: the MathScript Interactive Window and the MathScript Node. Additionally, this article touches on some of the features and debugging techniques of the MathScript Node.


NI does not recommend LabVIEW MathScript Module functions for new designs. See for information and recommended alternatives.


What Is the LabVIEW MathScript RT Module?

LabVIEW MathScript RT is an add-on module for the LabVIEW Full and Professional Development Systems. It is designed to natively add text-based signal processing, analysis, and math into the graphical development environment of LabVIEW. With more than 800 built-in functions, LabVIEW MathScript gives you the ability to either run your existing custom .m files or create them from scratch. Using this native solution for text-based math, you can combine graphical and textual programming within LabVIEW because the text-based engine is part of the LabVIEW environment. With LabVIEW MathScript RT, you can choose whether graphical or textual programming is most appropriate for each aspect of your application.

How Do I Use the MathScript RT Module?

There are two methodologies for interacting with the MathScript Engine: the MathScript Interactive Window and the MathScript Node.

Using the MathScript Interactive Window

The MathScript Interactive Window, accessed from the Tools menu, provides an intuitive interface to MathScript. With a command-line interface and a window to build batch files, the MathScript Interactive Window is designed to help you develop your scripts.

The Using the MathScript Window in LabVIEW tutorial familiarizes users with the capabilities of this tool.

Using the MathScript Node

The MathScript Node, accessed from the LabVIEW block diagram functions palette, provides an interface to MathScript that gives you the power to combine graphical and textual programming within the same LabVIEW application. By passing variables across the border of the structure, the MathScript Node is designed to help you deploy your scripts.

The Using the MathScript Node in LabVIEW tutorial familiarizes users with the capabilities of this tool.

MathScript Node: Additional Information

Script Highlighting

Script highlighting uses colors to distinguish between different parts of a script in a MathScript Node. These colors improve the readability of the script and help you debug a script that contains errors or returns unexpected data. For example, you can use script highlighting to see when a user-defined function or a variable overrides a built-in MathScript function. Script highlighting is enabled by default, except for MathScript Nodes that were last saved in a version of LabVIEW prior to LabVIEW 8.5, and uses custom colors.

MathScript Node offers Two types of script highlights: Syntax Highlighting and Data Type Highlighting.

  • Syntax Highlighting: Syntax highlighting displays script elements such as operators and comments in different colors. For example, if a variable or user-defined function overrides a built-in MathScript function, syntax highlighting colors that script element as a variable or user-defined function. You can customize the script highlighting colors for nodes in which it is enabled by using the Syntax section of the MathScript page of the Options dialog box: 

    Syntax highlighting

  • Data Type Highlighting: Data type highlighting displays the data types of variables in different colors and font attributes. Data type highlighting gives you the ability to see when the script redefines a variable from one data type to another.

Data type highlighting

Debugging Your Code Within the MathScript Node

You can perform in-node script debugging and use the MathScript probe to view intermediate variable values that are defined from within the node.

Using the MathScript Probe

Probes are invaluable tools for debugging LabVIEW applications because you can use them to see intermittent values. With the MathScript probe, you can debug your MathScript code by investigating unexpected results in the MathScript Node. You can use the probe to view the data in a MathScript Node as the VI runs. The probe displays a list of all variables you define in the script and previews variables you select. It also displays the output that MathScript generates from the script.

To view the MathScript probe, right-click inside a node and choose Probe (or just left-click over the node if the VI is running already).

MathScript probe


Using Breakpoints, Single Stepping, or Execution Highlighting in the MathScript Node

The MathScript Node also includes full debugging capabilities, including the following:


The gray region on the left side of the MathScript Node, used to interact with these tools, displays the following:

  • Red error glyphs next to lines of the script that contain an error
  • Warning glyphs
  • Breakpoints Block Diagram

Just like breakpoints in graphical code, the block diagram brings the specific line of code where the breakpoint exists into key focus, and the VI pauses. You can then execute single stepping and execution highlighting using the appropriate buttons on the LabVIEW toolbar. The error list window also lists the lines of code where an error exists. When you select the error within this window and click the Show Error button, LabVIEW highlights the line of script that contains the error.

What Does This Yellow “Exclamation Point” Glyph Mean?

The LabVIEW MathScript RT Module is engineered for optimal performance in a real-time OS. Unlike most .m file environments, the MathScript Engine takes the loosely typed .m file language and strictly types it within the context of the LabVIEW graphical environment for efficient data type propagation throughout the underlying code. This strict typing ensures that LabVIEW can efficiently compile the text-based MathScript code for edit-time semantic and syntax error handling as well as in-node context help. The MathScript Engine does a significant amount of work at “edit time” within the LabVIEW development environment. There is a subset of functions that, when included in a script, prevent the compiler from statically compiling the script. These include functions such as load, path, cd, and addpath, which introduce syntax not included in the node.

If you call these functions from a MathScript Node or a user-defined function, a warning glyph appears in the MathScript Node next to the line from which you call the function. Block Diagram

The warning glyph indicates that LabVIEW operates with reduced error checking and slower run-time performance for the MathScript Node. To improve the error checking and optimize the performance of the MathScript Node, remove this function from scripts and user-defined functions. Also, do not change the MathScript search path list at run time. Instead, use the MathScript Options page to configure the default search path list for MathScript Nodes in the main application.

Was this information helpful?