LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Averaging individual elements within a 2D array

I am trying to average each individual element within a 2D array.  How would I go about averaging continuously if the 2D array is constantly being updated through another while loop calculation?  Thank you in advance for  your help.

0 Kudos
Message 1 of 15
(2,769 Views)

How is the 2D sharing itself between the two loops?  Are you using a queue or some other means?  You need to be careful of race conditions.

 

Can you also describe the application in order to provide a better solution for your needs?  And can you show what you have so far?

0 Kudos
Message 2 of 15
(2,743 Views)

I tried to build something suitable for you according to your description. I take it you use a producer-consumer architecture as you referred to another while loop and the data that is transferred is a 2D array and you want to average its elements with another 2D array that is already available so basically you're constantly updating an available 2D array. My code [only the consumer loop is displayed] takes a 2D array from the queue, selects the specific element averages it and puts it into the other array.

 

I hope this is that you need.

 

Krivan

0 Kudos
Message 3 of 15
(2,729 Views)

Hi Krivan,

 

You would need a shift register on your while loop to do what you are intending. As it stands each iteration will send an empty array to your for loop. You can also do what your for loop is doing with:

 

Average 2d array.png

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
Message 4 of 15
(2,721 Views)

True. Shift register is corrected.

 

It is true that in could do it with that as well but in the original post a continuous update was required and I think the use of In Place requires less memory.

 

Krivan

0 Kudos
Message 5 of 15
(2,715 Views)

Hello krivan,

 

  I just briefly looked, but isn't there some missing of weights? I mean it goes something like this, in case of  2 averages :

   a/2 + (a/2 + b)/2

instead of  a/2 + b/2

 

Michael.

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 6 of 15
(2,703 Views)

I don't quite understand what you mean, the average of two numbers is (a+b)/2. In every averaging cycle you will always have only two numbers, consequently the same formula applies.

 

Krivan

0 Kudos
Message 7 of 15
(2,696 Views)

Just a quick point Krivan. Wasnt going to mention it but then thought you might actually want to know. Because you are initialising the shift register with an empty array, your output array will always be empty. Basically nothing will happen, your indexing places that don't exist.

 

Rgs,

 

Lucither.

------------------------------------------------------------------------------------------------------
"Everything should be made as simple as possible but no simpler"
0 Kudos
Message 8 of 15
(2,694 Views)

Krivan,

 

  In case of just averaging 1 value (not 2D) :

 

    First iteration of while loop: shift register has 0, value comes, say 1, shift register written 1/2.

    Second iteration of while loop: shift register has 1/2, value comes, say 1, shift register written (1/2 +1)/2 = 3/4

 

So you get an average of two values, each 1, and it equals to 3/4 instead of 1.

Am I wrong?

 

Michael.

 

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


Message 9 of 15
(2,681 Views)

Lucither: Yes thanks, this is why I appreciated it by a kudo ;-).

 

mishkylar: good point actually! Thinking about it the use of the mean pt-by-pt.vi probably would solve all the problem.

0 Kudos
Message 10 of 15
(2,667 Views)