This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Using the MathScript Window in LabVIEW

Updated Aug 28, 2023



  • LabVIEW
  • LabVIEW MathScript Module


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

The MathScript Interactive Window 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.
You can use the MathScript Interactive Window to enter commands one at a time. You also can enter batch scripts in a simple text editor window, load scripts from a text file, or import scripts from a separate text editor. The MathScript Interactive Window provides immediate feedback in a variety of forms, such as graphs and text.

This tutorial familiarizes users with MathScript Window and the different ways to input and run scripts. 

  1. Ensure that you have LabVIEW and the LabVIEW MathScript Module are installed before beginning.
    • Note that you must have the same version and bitness of LabVIEW and MathScript Module installed.
    • Note that MathScript Module is only compatible with Windows OS. Check the readme for your version of MathScript to determine compatible operating systems.
  2. Open LabVIEW.
  3. In the menu bar, select Tools » MathScript Window to open the MathScript Interactive Window.
Note: The following tips might be useful as you work in the LabVIEW MathScript Window.
  • Place the cursor in the Command Window and use the Up and Down arrow keys on the keyboard to scroll through the command history.
  • Right-click the Preview Pane on the Variables page and select Undock Window from the shortcut menu to display the variable in a separate window that you can resize.

Using the Command Window

  1. In the command window, enter 4+6+1. Then press the <Enter> key.
    • Examine the Output Window. LabVIEW displays the result of the command in the Output Window. You can enter commands one at a time for immediate feedback in this section.
    • Examine the Variables tab. LabVIEW updates the variable ans under the Local section in the Partition/Variable tree, to contain the result of the last command executed.
Note: You can use the command window to find more information about commands. For example, type help subplot in the window and a description of the command, along with information about syntax, inputs, outputs, and examples, appears.

Running Code in the Script tab

  1. Click the Script tab and enter the following commands:
x=linspace(0,2*pi, 30);
plot (x,b);axis([0 2*pi -20 20]);
Recognize that the x=linspace(0,2*pi,30); command creates a new variable x and populates that variable with 30 samples evenly distributed between 0 and 2*pi.
  1. Click the green Run arrow on the Script page. The Plot 1 window appears and displays an XY plot of x versus b.
  1. Click the Variables tab to display variables you create, such as x and b.
  2. Select b from the Partition/Variable tree. A table representing the numeric values of appears.
  3. Select the Graphical First? checkbox to change the numeric display to a graph display. 


Loading and Running a .m File

  1. Download the attachment signalprocessing.m¹ available at the bottom of this document. This script generates a test signal and then applies a moving-average filter to the test signal.
  2. In the MathScript Window, click the Script tab and select Open. Navigate to the location of the downloaded the .m file, and select signalprocess.m.
  3. Click Run. The Prompt User for Input dialog box appears. Enter a positive value in the Desired length of the filter = text box and click the OK button.
    • Note: MathScript scripts can include interactive dialog boxes to request user input.
The Plot window surfaces again. The signalprocess.m script uses subplot commands to specify four subplots. Note that a​​​fter a subplot is specified, subsequent commands affect that subplot. For example, a plot command, following a subplot command, populates the data specified in the subplot command with the data specified in the plot command. Examine the code excerpt from the signalprocessing.m file below which correlates with the Signal #1 subplot.
plot(n, s1);
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');
title('Signal #1');

Next Steps

Exporting LabVIEW MathScript Window Data to a Text or Spreadsheet Program (MathScript RT Module)