How Can I Calculate the Mean of a 2D Array in LabVIEW?

Updated Mar 31, 2021

Reported In

Software

  • LabVIEW

Issue Details

I would like to calculate the mean of all elements in a 2D array. I tried to use Mean.vi, but it seems to only accept a 1D array as its input. Is there a function that would do the same for a 2D array?

Solution

Unfortunately, there is not a function that is designed to calculate the mean of a whole 2D array by itself. Therefore, you would need to come up with your own algorithm for that. Below is one way of doing it.
  1. Calculate the sum the 2D array by using Add Array Elements.vi
  2. Calculate the size of the 2D array by using Array Size.vi, which returns the number of elements of each dimension in 1D array
  3. Calculate the total number of elements in the 2D by multiplying the elements, calculated at Step 2., by using Multiply Array Elements.vi
  4. Divide the output of Add Array Elements.vi by that of Multiply Array Elements.vi 

2D Array.png

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.

Additional Information

This technique can extend to 3D arrays and greater dimensions.