01-13-2011 03:01 PM
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.
01-13-2011 09:21 PM
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?
01-14-2011 04:42 AM
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
01-14-2011 04:56 AM
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:
Rgs,
Lucither.
01-14-2011 05:03 AM
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
01-14-2011 05:28 AM
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.
01-14-2011 05:35 AM
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
01-14-2011 05:37 AM
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.
01-14-2011 05:50 AM
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.
01-14-2011 06:08 AM
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.