08-08-2014 12:34 PM
Hello,
I have a while loop that collects data from a DAQ Assistant and stores it into a 1D array. The number of loops is set by the user. I am trying to average the data from each iteration of the loop. So far I am only able to get the array to overwrite the previous array values with the new ones.
if Number of loops = 3
First Iteration Second Iteration Third Iteration New 1D Array [Divide by Loop #
4.97 4.99 4.98 14.94 for the average]
4.97 4.99 4.98 14.94
4.96 4.98 4.97 14.91
4.98 5.00 4.99 14.97
4.97 4.99 4.98 14.94
I would like to make this as general as possible as the loop number will vary depending on the user input.
Solved! Go to Solution.
08-08-2014 01:05 PM
please post VI
08-08-2014 01:05 PM
Notice that the tool to sum an entire array is built into labview. Divide by the array length and you have the average.
Study labview array behavior and auto indexing for powerful ways to do common array tasks. For example, if you wire an array to the multiply icon, the output is a new array containing the product of EVERY element of the array and the multiplier. No need to use a loop at all!
08-08-2014 01:17 PM - edited 08-08-2014 01:18 PM
If I understand you correcty, you could use a shift register to store your final array. Then just sum each time you calculate an array. Lastly take the average by dividing by the size (user specified for the for loop).
This is a rough example of what I mean:
08-08-2014 01:18 PM
I like the creative solution you have provided however, I am trying to keep the average at each element so that I can graph the average at each point. Therefore, I need the average to be a 1D array of the same initial length, not a scalar.
I am trying to avoid using shift registers.
08-08-2014 01:20 PM - edited 08-08-2014 01:20 PM
@sgtpppr685 wrote:
I like the creative solution you have provided however, I am trying to keep the average at each element so that I can graph the average at each point. Therefore, I need the average to be a 1D array of the same initial length, not a scalar.
I am trying to avoid using shift registers.
1. Do you mean you want the average after each iteration as well? This can be done pretty easily by moving the division inside my loop. Perhaps I am misunderstanding you though.
2. Why avoid shift registers? They are amazing and effective. They are an essential LabVIEW tool imo 😛 Plus they work wonderfully for your current problem.
08-08-2014 01:24 PM
I will post my VI, just let me clean it up a bit. Shift Registers are not my friend today.
08-08-2014 01:33 PM
You absolutely should be using shift registers here. How else is iteration 2 going to know what values existed during iteration 1????
If you add two arrays (just the basic math operation) they add by index (index 2 + index 2) then just divide by the number of loops after the for loop has finished.
If you want to calculate the moving average (update average during the loops) you'll need to employ a moving average algorithm... NOTE that simply dividing by the iteration number here will give you the WRONG RESULTS.
08-08-2014 01:36 PM
@pjr1121 wrote:
If you want to calculate the moving average (update average during the loops) you'll need to employ a moving average algorithm... NOTE that simply dividing by the iteration number here will give you the WRONG RESULTS.
Good catch! I stand corrected on that part 😛 Its been a while since I worried about means.
08-08-2014 01:40 PM
I am using Labview 2011
I have tried using shift registers and because I exit the loop, a feedback node appears and it seems to be nullifying the array instead of storing the data. Perhaps I just don't understand how to properlyy use a feedback node.
Thank you for all the help so far. I've really been pulling my hair out.