LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

averaging rows in an array

I am trying to find the average of an array, but I need the average of the rows of each.  I don't know what function to use, because the only ones I can find take the average of the whole array.  I can't split up the array because there are a variable number of inputs that changes each time the array runs through a for loop where the user specifies the numer of times that the loop is run.
0 Kudos
Message 1 of 10
(39,741 Views)

You should just use a for loop to index through each row of the array, and allow the mean function average the row, then rebuild the array.

Message Edited by Ravens Fan on 04-15-2007 10:06 PM

Message 2 of 10
(39,734 Views)
There is a much faster possibility by using matrix multiplication. The function is called "A x B". See also attached image. The speed was faster by a factor of 13.
Download All
Message 3 of 10
(38,716 Views)

biddy wrote:
There is a much faster possibility by using matrix multiplication. The function is called "A x B". See also attached image. The speed was faster by a factor of 13.

 

 

Nice solution! Don't forget to divide by the number of rows (size of the vector) when using this method.

 

0 Kudos
Message 4 of 10
(38,675 Views)

Interesting behavior, though I found it to be limited. With larger arrays the time difference decreases, and actually reverses (with the AxB taking longer). At some point (in my case it was a 500x500 array) the A x B VI produces an out of memory error, but the Mean VI still works.

 

UPDATE: Make that  300x300. I actually got LabVIEW to crash on that AxB VI at that point. Smiley Surprised

Message Edited by smercurio_fc on 05-07-2009 09:03 AM
0 Kudos
Message 5 of 10
(38,672 Views)
Try using an input array of random data.  Seems to tip the scales a bit as well.
0 Kudos
Message 6 of 10
(38,660 Views)

Hi,

 

So I tried using the mean method given above, but the mean function seems to be thinking I am giving it a 2d array when I believe the for loop is just giving it a row. Can someone see if my syntax is a little funky? I may possibly be in the way I am building my array, which is being built in a for loop itself.

 

Michael

0 Kudos
Message 7 of 10
(36,961 Views)

It is because you are creating a 3-D array, which becomes a 2-D array when you auto-index it at the for loop which has the mean function.

 

The problem is probably originating in  your 3rd sequence frame.  There you are taking a 1-D array and building it onto a 2-D array through the feedback node.  But the output of the for loop is auto-index which means it takes every loop iteration of that 2-D array and makes it a 3-D array.  I really don't know what your data means, or what you are trying to do, but I really doubt that is what you want.

0 Kudos
Message 8 of 10
(36,939 Views)

Hi,

 

So that 1-D array contains strings of numbers in exponent form. What I am wanting to do is take that array and average it with the other 9 arrays (by row) that will get produced in the for loop. Does that make sense? I am having trouble figuring out the best way to store the data to do the averaging, which is why I thought of maybe taking the mean each time.

 

 

0 Kudos
Message 9 of 10
(36,933 Views)

mcoughlin wrote:

Hi,

 

So that 1-D array contains strings of numbers in exponent form. What I am wanting to do is take that array and average it with the other 9 arrays (by row) that will get produced in the for loop. Does that make sense? I am having trouble figuring out the best way to store the data to do the averaging, which is why I thought of maybe taking the mean each time.


moved here

0 Kudos
Message 10 of 10
(36,887 Views)