LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Average values from multiple 2D arrays

Solved!
Go to solution

Hi,

 

I'm trying to figure out how one would go about averaging values from an N number of 2D arrays, as in all the values of [1,1] averaged, then [1,2] ect to result in a final 2D array of averaged values. All the 2D arrays will be the same size. 

______________________________________________________________


______________________________________________________________
0 Kudos
Message 1 of 8
(5,811 Views)

Can you explain what you mean?
Example in values?
Or if you want get average of one-two-three etc first elements, you can reshape your 2D array to 1D array and then take first 1-2-3... elements.

0 Kudos
Message 2 of 8
(5,799 Views)

How are the N arrays presented to you....as a 3D array?  If so, it sounds like you just need a series of nested for loops to index the values, average them and autoindex them back into another array.  Seems fairly straight forward if i understand your requirements.

aputman
0 Kudos
Message 3 of 8
(5,790 Views)

Basically, instead of indexing a row or column, you would be indexing a "page" as they are called.  So normally to index a whole row in a 2D array, you leave the column empty and a 1D array of values is returned.  WIth a 3D array, you leave the page value blank and specify a row, column and it will return a 1D array of values that span in the Z direction, if you want to call it that. 

 

So for example, these are your 3 2D arrays that are essentially stacked on top of one another. 

1 1 1

1 1 1

1 1 1

 

2 2 2

2 2 2

2 2 2

 

3 3 3

3 3 3

3 3 3

 

Index this 3d array with the row and column set to 0 and the page value blank will return 1, 2, 3 (which is the values in the 0,0 position from all 3 arrays). 

aputman
0 Kudos
Message 4 of 8
(5,779 Views)

Here is one way to do it.  There may be another more efficient method than this....actually I'm fairly positive that is the case....I jus don't know what it is.  Smiley Wink

Example_VI_BD.png

aputman
0 Kudos
Message 5 of 8
(5,762 Views)
Solution
Accepted by topic author Gazebo

Here is a one loop method. Add pages and divide by the number of pages.

 

Lynn

0 Kudos
Message 6 of 8
(5,736 Views)

I would just sum them up in a shift register, e.g. as follows, then divide by the number of iterations:

 

 

 

It would be easy to adapt to other data structures and works equally wel to average 1D or 3D arrays, etc..

 

How is your original data arranged? If it is a 3D array, replace the while loop with an autoindexing FOR loop and devide after the loop has completed. Modify as needed.*

 

*EDIT: This is exactly as Lynn suggested. 😄

Download All
0 Kudos
Message 7 of 8
(5,731 Views)

Thank you all for your help. Lynn's VI is perfect.

______________________________________________________________


______________________________________________________________
0 Kudos
Message 8 of 8
(5,701 Views)