This content is not available in your preferred language.

The content is shown in another available language. Your browser may include features that can help translate the text.

Create a 2D Array in LabVIEW

Updated Oct 22, 2023

Environment

Software

  • LabVIEW

When adding an array in LabVIEW, it is by default a 1-D array. How can I add an array of Two Dimensions?
 

It is possible to create a 2D-Array from the Block Diagram and Front Panel. Let´s see the process on each one: 


Front Panel

  1. Launch LabVIEW and open a VI
  2. Right-click on the front panel and add the Controls >> Data Containers >> Array to your front panel, then define its data type.
  3. Add a dimension to an array by either:
    • Right-clicking on the index display (to the left of the array) >> select Add Dimension from the shortcut menu.
    • Or dragging the index display until the number of index displays matches the desired number of dimensions. (i.e. For a 2-D array, drag until 2 displays are visible)

Block Diagram

  1. Launch LabVIEW and open a VI.
  2. Right-click on the block diagram and add the Array >> Initialize Array function in the array palette.
    • By default, the Initialize Array function is set up to create a 1-D array.
  3. Left-click the Initialize Array function so the blue resizing nodes appear. 
  4. Click and drag the bottom blue node to resize the function until you have the number of dimensions you need to be shown. (i.e. For a 2-D array, drag until 2 displays are visible)
  5. Define the number of elements you would like in each dimension. 
    1. Right-click the first dimension size input >> Create Constant to define the number of rows in your array.
    2. Right-click the second dimension size input >> Create Constant to define the number of columns in your array.
  6. Add a constant of your desired data type to the element input. This will fill in all elements throughout your array.
    • In the example below, there are 5 rows and 2 columns defined in the 2D array. The array will be filled with string datatype elements, initialized to all say "hello."
  1. Right-click the initialized array output of the function and select Create Indicator.
  2. On the front panel, hover over the bottom-left resizing node of the array indicator until the multi-dimensional array resizing node appears. Resize array.
    • Resizing to larger than your specified dimensions is fine. When the program is run, only the array elements within your specified row and column dimensions will be initialized.
  3. Run the VI to initialize your 2D array.