Company Events Academic NI Developer Zone Support Solutions Products & Services Contact NI MyNI

Organizing Related Data in Variables (MathScript RT Module)

LabVIEW 2011 MathScript RT Module Help

Edition Date: June 2011

Part Number: 373123B-01

»View Product Info

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.

Defining Structure Arrays

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';

Comparing Structures to Clusters

MathScript structures differ from LabVIEW clusters in the following ways:

  • Different elements in an array of structures can have different sets of fields.
  • Field names must begin with an alphabetic character and can contain only alphanumeric characters and underscores.
  • Fields in different elements of structure arrays can contain different data types; however, there are restrictions to this behavior.

Passing Structures into a MathScript Node

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:

  • You must label individual elements of the cluster. Labels must start with an alphabetic character and can contain only alphanumeric characters and underscores without any spaces.
    Note  You can use the function is_validvarname to validate cluster element labels.
  • Use the following data types for individual elements of the cluster:
    • Scalar, 1D array, or 2D array of the following data types:
      • Boolean
      • Numeric
      • (Control Design and Simulation Module) State-space model, zero-pole-gain model, or transfer function model
    • Scalar or 1D array of strings
    • Real matrix
    • Complex matrix
    • Cluster that meets the conditions for individual elements of a cluster

If you do not follow these conditions, the wire to the input of the MathScript Node breaks.

Passing Structures out of a MathScript Node

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:

  • Scalar, 1D array, or 2D array of the following data types:
    • Boolean
    • Numeric
    • (Control Design and Simulation Module) State-space model, zero-pole-gain model, or transfer function model
  • 1D or 2D array of strings
  • Structure that meets the conditions for individual elements of a structure

If you do not follow these conditions, the output terminal to the MathScript Node breaks.

Avoiding Different Data Types in Corresponding Fields of a Structure Array

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.


 

Your Feedback! poor Poor  |  Excellent excellent   Yes No
 Document Quality? 
 Answered Your Question? 
Add Comments 1 2 3 4 5 submit