You can use structures, or structs, to organize related data in variables. The following example shows how to define a structure with multiple fields that describe a point within a graph or plot:
point.x = 3.0;
point.y = 4.0;
point.color = 'blue';
In this example, point is a scalar structure with three fields: x, y, and color. Each field has an assigned value of either numeric or string data type.
You can define structure arrays in which each element is a structure with multiple fields. The following example shows how to define two structure elements that describe points:
point(1).x = 3.0;
point(1).y = 4.0;
point(1).color = 'blue';
point(2).x = 3.5;
point(2).y = 5.0;
point(2).color = 'green';
MathScript structures differ from LabVIEW clusters in the following ways:
You can pass LabVIEW clusters into a MathScript Node. If the following conditions are true, a cluster becomes a structure in the MathScript environment with fields that have the same names and values as the names and values of the individual elements of the cluster:
![]() | Note You can use the function is_validvarname to validate cluster element labels. |
If you do not follow these conditions, the wire to the input of the MathScript Node breaks.
You can pass structures out of a MathScript Node under the condition that you use the following data types for individual elements of the structure:
If you do not follow these conditions, the output terminal to the MathScript Node breaks.
When passing structures out of a MathScript Node, you cannot use different data types in corresponding fields of a structure array or the output terminal to the node breaks. The following example shows different data types in fields of a two-element structure array:
a(1).b = 5;
a(2).b = 'string';
In structure a(1), the data type of field b is integer. In structure a(2), the data type of field b is string. LabVIEW does not coerce an integer to a string, so the structure does not pass out of the node.