Use script nodes to execute math scripts in LabVIEW. LabVIEW provides script nodes for the LabVIEW MathScript syntax, the MATLAB® language syntax, and the Xmath syntax. The MathScript Node, MATLAB script node, and Xmath script node are similar to the Formula Node, but they allow you to import an existing LabVIEW MathScript, script written in the MATLAB language syntax, or Xmath script in ASCII form and run the script in LabVIEW. As with a Formula Node, you can pass data to and from the node.
![]() |
Tip Short scripts work well with the Formula Node because the Formula Node executes faster than the MathScript Node. |
You can use the MathScript Node to create, load, and edit LabVIEW MathScripts and scripts written in the MATLAB language syntax on the block diagram, even if you do not have the MATLAB software installed on your computer. However, the MathScript engine executes the scripts in the MathScript Node, and the MathScript engine does not support some functions that the MATLAB software supports. If you have a licensed copy of the Xmath software or a licensed copy of the MATLAB software version 6.5 or later installed on your computer, you can use the Xmath script node or the MATLAB script node to create, load, and edit Xmath scripts or scripts written in the MATLAB language syntax on the block diagram.
![]() |
Note The MathScript Node, MATLAB script node, and Xmath script node are available only on Windows. |
Use input and output variables on the script nodes to pass values between LabVIEW and MathScript, the MATLAB software, or the Xmath software. The structure of an expression in a script determines whether a variable is an input or an output. For example, if the script contains the assignment statement, X = i + 3, you can create an input variable i on the script node to control how the script node calculates X, and you can create an output variable X on the script node to retrieve the final result of the script calculation.
![]() |
Note You can create script nodes only in the LabVIEW Full and Professional Development Systems. If a VI contains a script node, you can run the VI in all LabVIEW packages. |
If you do not already have a script written, you can place a script node on the block diagram and create a script using MathScript syntax, the MATLAB language syntax, or Xmath syntax. The LabVIEW Full and Professional Development Systems install the MathScript engine that runs scripts for MathScript. The MATLAB software and the Xmath software install script server engines that run scripts written in the MATLAB language syntax and Xmath syntax, respectively. LabVIEW communicates with the respective script server engine through the corresponding script node. You can change the script server engine with which LabVIEW communicates to convert a MATLAB script node to an Xmath script node or to convert an Xmath script node to a MATLAB script node. Right-click the border of a MATLAB script node or Xmath script node and select Choose Script Server»Xmath script or Choose Script Server»MATLAB script from the shortcut menu to convert a MATLAB script node or Xmath script node. You cannot change the script server engine for a MathScript Node.
The MATLAB script node and Xmath script node cannot determine the data type of input and output variables you create. You must assign a LabVIEW data type to each script node input and output variable. MathScript Nodes can determine the data type of input variables but not output variables. The following table shows LabVIEW data types and the corresponding data types in the MATLAB script node, Xmath script node, and MathScript Node.
| LabVIEW Data Type | MATLAB Script Node | Xmath Script Node | MathScript Node |
|---|---|---|---|
|
Double-precision, floating-point numeric |
Real | Real Scalar | Scalar»DBL |
|
Complex double-precision, floating-point numeric |
Complex | Complex Scalar | Scalar»CDB |
|
1D array of double-precision, floating-point numeric |
1-D Array of Real | 1-D Array of Real | 1D-Array»DBL 1D |
|
1D array of complex double-precision, floating-point numeric |
1-D Array of Complex | 1-D Array of Complex | 1D-Array»CDB 1D |
|
Multidimensional array of double-precision, floating-point numeric |
2-D Array of Real | 2-D Array of Real | Matrix»Real Matrix (2D only) |
|
Multidimensional array of complex double-precision, floating-point numeric |
2-D Array of Complex | 2-D Array of Complex | Matrix»Complex Matrix (2D only) |
|
String |
String | String | Scalar»String |
|
Path |
Path | N/A | N/A |
|
1D array of string |
N/A | String Array | 1D-Array»String 1D |
![]() |
Note You also can use the state-space, transfer function, and zero-pole-gain models of the LabVIEW Control Design Toolkit with the MathScript Node and the Xmath script node. The Xmath software supports only the SISO versions of the transfer function model and the zero-pole-gain model, but LabVIEW MathScript supports all versions of the models. You must have the LabVIEW Control Design Toolkit installed to use these models. Refer to the LabVIEW Control Design Toolkit documentation for more information about these models. |
The MathScript Node and the MATLAB script node handle 1D array inputs only by row, and the Xmath script node handles 1D array inputs only by column. To change the orientation of a 1D array from row to column or column to row, transpose the array before you perform operations on elements of the array.
Use the Conversion VIs and functions or the String/Array/Path Conversion functions to convert a LabVIEW data type to a data type that MathScript, the MATLAB software, or the Xmath software supports.