Overview
This document provides information on the new features in LabVIEW 8.6 for using textual math with LabVIEW graphical programming. Refer to the LabVIEW Upgrade Notes in the "Related Links" section for a complete list of new features in LabVIEW 8.6.
Table of Contents
What Is LabVIEW MathScript?
LabVIEW MathScript adds math-oriented, textual programming to the LabVIEW graphical system design platform. At the heart of LabVIEW MathScript is a high-level text-based programming language with syntax and functionality that abstract the complexity of tasks related to signal processing, analysis, and math. LabVIEW MathScript is generally compatible with the .m file script syntax, which is widely used by alternative tools such as The MathWorks, Inc. MATLAB® software and others. This compatibility means that you can work with many previously developed .m file scripts, such as those available in engineering textbooks or on Web sites that distribute open-source .m file scripts.
With LabVIEW, you can choose the most effective syntax, whether you are developing algorithms, exploring signal processing concepts, or analyzing results. You can work with MathScript through both an interactive interface and a programmatic interface. For an interactive interface in which you can load, save, design, and execute .m file scripts, use the LabVIEW MathScript Window. To deploy .m file scripts as part of a LabVIEW application and to combine graphical and textual programming, use the MathScript Node.
Refer to the "Inside LabVIEW MathScript" Developer Zone document (see "Related Links" below) for more background information on LabVIEW MathScript.
Refer to the LabVIEW MathScript Online Evaluation Beta (see "Related Links" below) to test a .m file script in MathScript before you purchase LabVIEW.
Improvements to MathScript in LabVIEW 8.6
LabVIEW 8.6 improves on the experience of combining graphical and textual programming within LabVIEW by adding the following features to the Full and Professional packages:
- Functional improvements
- Debugging
- Script highlighting
- New platform support
Along with these new features, the VI Hierarchy window now displays .m files you reference from within MathScript Nodes.
Functional Improvements
LabVIEW 8.6 includes 39 new functions in core LabVIEW MathScript. These functions are spread among 14 different classes, including approximation, filter design, waveform generation, and 16 new functions in the spectral analysis class. A few of these functions are:
- yulewalk - Creates a recursive IIR filter using a time-domain least-squares fit
- spectrogram - Creates a spectrogram of an input signal using the short-time Fourier transform
- rooteig - Calculates the frequency and power content of an input signal using the eigenvector method
- gaussfir - Creates an FIR Gaussian pulse-shaping filter
Refer to the "Abridged NI LabVIEW MathScript Function List" Developer Zone document (see "Related Links" below) for a summary of the functional coverage LabVIEW MathScript provides and a comprehensive list of new MathScript functions in LabVIEW 8.6.
Debugging in the LabVIEW MathScript Node
LabVIEW 8.5 added the ability to perform in-node script debugging and provided the MathScript probe to view intermediate variable values that were defined from within the node. LabVIEW 8.6 improves on these features by adding full debugging capabilities to the LabVIEW MathScript Node. These debugging capabilities include:
- Breakpoints
- Single stepping
- Execution highlighting
The new 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

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 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.
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 previous version of LabVIEW, and uses custom colors.
To enable or disable script highlighting for a particular MathScript Node, right-click inside the node and select Enable Script Highlighting or Disable Script Highlighting from the shortcut menu. To enable or disable script highlighting for all MathScript nodes or to customize the script highlighting colors for nodes in which it is enabled, use the MathScript: Script Highlighting page of the Options dialog box:

MathScript on Mac OS and Linux® OS
MathScript in LabVIEW 8.6 has now expanded to both the Mac OS and Linux platforms. This includes both the MathScript Node and the Interactive MathScript Window. The small subset of the MathScript functions that are not supported on these platforms is shown in the following table.
|
MathScript Function |
Mac OS |
Linux |
|
aich |
– |
|
|
aiwf |
– |
|
|
aoch |
– |
|
|
aowf |
– |
|
|
calllib |
– |
– |
|
dioread |
– |
|
|
diowrite |
– |
|
|
dos |
– |
– |
|
ginput |
– |
– |
|
gtext |
– |
– |
|
libfunctionsview |
– |
– |
|
libisloaded |
– |
– |
|
loadlibrary |
– |
– |
|
pause |
– |
– |
|
system |
– |
– |
|
unloadlibrary |
– |
– |
|
waitforbuttonpress |
– |
– |
Note: The getfileproperty function, the load function, the save function, and the setfileproperty function are available on Mac OS and Linux. However, you cannot use these functions with binary measurement files (.tdm or .tdms).
Improvements to MathScript in LabVIEW 8.5
LabVIEW 8.0 includes the ability to combine graphical code and textual math with LabVIEW MathScript. LabVIEW 8.5 improves this ability with the following new features:
-
70 new functions
-
MathScript Node probing
-
Error checking
-
Plotting improvements
-
Environment improvements
Functional Improvements
LabVIEW 8.5 includes 70 new functions in core LabVIEW MathScript. These functions are spread among 16 different classes, including approximation, DSP, integration, linear algebra, plots, and polynomials. A few of these functions are:
-
lookfor – Searches for all occurrences of the input string in the help topics for MathScript functions and in all .m files in the MathScript search paths.
-
fzero – Uses a nonlinear equation solver to determine the roots of the input function.
-
interpft – Uses the Fourier transform to perform 1D interpolation.
-
wavrecord – Records audio signals using Windows audio capabilities.
-
polyder – Generates the symbolic derivative of a polynomial or rational polynomial.
-
pareto – Generates a Pareto plot.
Refer to the "Abridged NI LabVIEW MathScript Function List" Developer Zone document (see "Related Links" below) for a summary of the functional coverage provided by LabVIEW MathScript and a comprehensive list of new MathScript functions in LabVIEW 8.5. The LabVIEW Control Design and Simulation Module includes 19 additional functions for MathScript. A few of these functions are:
-
ord2 – Creates a second-order system.
-
drtf – Creates a random discrete transfer function model.
-
isstable – Determines whether a system is stable.
Refer to the Embedded Control Engineering Web page (under the Related Links section below) for more information about this module.
Using the LabVIEW MathScript Probe
Probes are invaluable tools for debugging LabVIEW applications because you can use them to see intermittent values. LabVIEW 8.5 introduces this same functionality to the MathScript Node. With the LabVIEW MathScript probe, you can debug your LabVIEW applications by investigating unexpected results in the MathScript Node. You can use the LabVIEW MathScript probe to view the data in a script in a MathScript Node as a VI runs. The MathScript probe displays a list of all variables you define in the script and previews variables you select. The MathScript probe also displays the output that MathScript generates from the script.
Refer to the Using the LabVIEW MathScript Probe topic in the LabVIEW Help (see "Related Links" below) for more information about using the MathScript probe to help you debug a script in a MathScript Node. The LabVIEW MathScript Probe window includes the same components as the Variables page in the LabVIEW MathScript Window, as shown in the following screenshot.
Error Checking in the MathScript Node
In LabVIEW 8.2 or earlier, you cannot debug scripts in a MathScript Node without running the VI. All error checking occurs at run time. In LabVIEW 8.5, the MathScript Node performs some error checking at edit time. Click outside of the MathScript Node frame. Then click the broken Run button to display the Error list window.
The details section offers both a description of the error and the line number in which the error occurred. An unknown symbol error means that the symbol is not one of the following types of objects:
-
Variable
-
Local function
-
User-defined function
-
Native LabVIEW MathScript constant
-
Native LabVIEW MathScript functions
LabVIEW MathScript searches for the unknown symbol in the previously listed order. Depending on which of the above objects you are trying to reference, you can take different actions to correct the error. For example, if you want to reference a native MathScript constant, the unknown symbol error indicates that either the constant is misspelled or MathScript does not support the constant. Two of the more common cases in which this error appears are when you call a previously defined variable or a user-defined function.
Errors Associated with Variables
If you want to reference a variable, the unknown symbol error means that the variable is not currently defined. The variable name might be misspelled in the script or in the variable definition, or the variable might not be defined in the current MathScript Node. All local variables are cleared when the MathScript Node is finished executing. Therefore, if you need to pass a variable between two MathScript Nodes, either define the variable in each script as global or wire the variable as an input/output between the two scripts.
Errors Associated with User-Defined Functions
When you call a user-defined function, you might encounter errors. This specific error typically implies that the user-defined function is not defined correctly. Assuming that the user-defined function has indeed been created, and exists on disk somewhere, this means that LabVIEW does not see its path as a search path. The best solution is to add the search path for the user-defined function. Right-click on My Computer within the Project Explorer window and select Properties to open the My Computer Properties dialog box. Select MathScript: Search Paths from the Category list on the left.
This window defines all of the search paths that LabVIEW MathScript searches for within the LabVIEW Project. The top path in this window specifies the working directory. Use the buttons at the top to add, delete, or reorder the search paths. Once you add the user-defined function search path to the MathScript: Search Paths list, LabVIEW MathScript recognizes the function inside of the MathScript Node. It also performs edit-time semantic and syntactical error checking on the function itself. For example, in the image below, the script is calling a function hypotenuse. This function takes the square root of the sum of the squares of the two inputs, assuming the two inputs are the lengths of the triangle sides. However, the MathScript function sqrt has been misspelled.

The Error list window in the previous figure shows that the user-defined function hypotenuse that you are trying to call contains an error in Untitled 4.vi. By selecting hypotenuse.m from the Items with errors list, you see that on line 3, there is an unknown symbol, srt. This should be sqrt. You then can either browse to hypotenuse.m on disk or use the Dependencies in the Project Explorer window.
Any .m file that is referenced in a MathScript Node in the project shows up under the project Dependencies. Double-click the .m file to open the file.
The improvements to MathScript in LabVIEW 8.5 make working with .m file scripts within the graphical programming environment easier than ever. By using edit-time error checking and .m file script integration with the LabVIEW Project, you can incorporate your algorithms seamlessly into LabVIEW.
Plotting
LabVIEW MathScript takes advantage of the easy-to-edit graphing style of LabVIEW. With more than 70 different plot types, LabVIEW MathScript can help you visualize your data through contour, mesh, logarithmic, scatter, stem, surface, and many other plots. Each of these plot objects contains plot properties such as color, line width, and line style, which you can edit from the plot window, as shown in the following screenshot.
However, you might not want to set these properties interactively all the time. Programmatically setting properties is often the most efficient method of manipulating plot properties. LabVIEW 8.5 introduces the get and set MathScript functions. With these functions, you can find and change the attributes of MathScript plots, including the following attributes:
-
Color
-
Line style
-
Line width
-
Marker style
-
Marker size
-
Line type
-
Visibility
-
X data
-
Y data
Refer to the get and set function topics in LabVIEW Help (see "Related Links" below) to find the appropriate syntax and values to change these plot attributes. You also can use the Variables page in the LabVIEW MathScript Window to change the plot attributes. You can change these attributes through pull-down menus in the Preview Pane of the LabVIEW MathScript Window.
With the addition of the get and set functions to LabVIEW MathScript, you can set plot properties both programmatically and interactively. LabVIEW MathScript also makes it easy to export the plot to use in any common reporting application.
Environment Improvements
In LabVIEW 8.2 or earlier, one issue with using LabVIEW MathScript was that it was difficult to transition between MathScript and other LabVIEW files, such as LabVIEW projects and VIs. In LabVIEW 8.5, the LabVIEW MathScript Window shares the same toolbar as other LabVIEW windows, so you can browse examples, open recent project files, and display the Context Help window from the LabVIEW MathScript Window. Also, you can resize individual sections of the LabVIEW MathScript Window, such as the Command Window and the Output Window. To resize a section, move the splitter bar located between the two sections you want to resize. This feature makes it easier to view large text outputs in the Output Window and to create long scripts in the Script Editor.
Related Links
Learn more about new features in the latest version of LabVIEW
Try new features now, Launch LabVIEW online
Developer Zone: Abridged NI LabVIEW MathScript Function List
Developer Zone: Developing Algorithms Using LabVIEW MathScript: Part 1, The LabVIEW MathScript Node
Developer Zone: Developing Algorithms Using LabVIEW MathScript: Part 2, The MathScript Interactive Window
Developer Zone: Inside LabVIEW MathScript
LabVIEW Upgrade Notes
LabVIEW Help: get
LabVIEW Help: set
LabVIEW Help: Using the LabVIEW MathScript Probe
NI Discussion Forums: LabVIEW MathScript Discussion Forums
Embedded Control Engineering
MATLAB® is a registered trademark of The MathWorks, Inc. All other trademarks are the property of their respective owners.
Reader Comments | Submit a comment »
3D arrays is still not supported
somehow with MathScript
- bernardino.buenaobra@ph.global-imi.com - Sep 16, 2008
Looks like its almost like MatLab now and its
really nice with exception that up to now
MathScript cannot script and operate more
than 2D. There is no way to increase to
N-dimension via usual array script inside it
- no 3D volume array calculations permitted
except graphing a mesh.
- Berns Buenaobra, IMI Philippines . bernardino.buenaobra@ph.global-imi.com - Sep 2, 2008
Nice description
I'm impressed by the clarity of the
explanations, especially the example of
debugging the misspelling of sqrt.
- attasm@aecl.ca - Aug 15, 2007
Legal
This tutorial (this "tutorial") was developed by National Instruments ("NI"). Although technical support of this tutorial may be made available by National Instruments, the content in this tutorial may not be completely tested and verified, and NI does not guarantee its quality in any way or that NI will continue to support this content with each new revision of related products and drivers. THIS TUTORIAL IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND AND SUBJECT TO CERTAIN RESTRICTIONS AS MORE SPECIFICALLY SET FORTH IN NI.COM'S TERMS OF USE (http://ni.com/legal/termsofuse/unitedstates/us/).
