- 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.
- Open LabVIEW.
- In the menu bar, select Tools » MathScript Window to open the MathScript Interactive Window.
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
- 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.
: 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
- Click the Script tab and enter the following commands:
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.
- Click the green Run arrow on the Script page. The Plot 1 window appears and displays an XY plot of x versus b.
- Click the Variables tab to display variables you create, such as x and b.
- Select b from the Partition/Variable tree. A table representing the numeric values of b appears.
- Select the Graphical First? checkbox to change the numeric display to a graph display.
Loading and Running a .m File
- 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.
- 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.
- 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 after 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
axis([0, 100, -2, 2]);
xlabel('Time index n'); ylabel('Amplitude');