Calculate the Sum of Each Row or Column in a LabVIEW 2D Array

Updated Jun 7, 2024

Reported In

Software

  • LabVIEW Base
  • LabVIEW Full
  • LabVIEW Professional

Issue Details

I want to calculate the sum of each row or column in a 2D array.

Solution

A row or a column of a 2D array is also a 1D array. In LabVIEW you can use the Add Array Elements function from the Numeric Palette to calculate the sum of a 1D array. Use this function in a For Loop and connect the input array and also the output array with Auto-Indexed Tunnels.
 
  • If you need to calculate the sum of the rows you need to connect the array to the For Loop directly:
 
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.
 
  • If you need to calculate the sum of the columns you need to connect the array to the For Loop through the Transpose 2D Array function:
  
Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.