07-13-2010 04:11 PM
So, this seems like a simple problem, but I couldn't find anything that really helped me by searching these forums. I apologize if this is a redundant question.
Right now I have an X and a Y coordinate that are varying and I'm hoping to find a rolling average of each. I've been trying to use a queue to find this average, but when I attempt to flush the queue, I end up with an array of one value. For some reason, the queue doesn't seem to be populating correctly. What am I doing wrong?
I've attached a picture of my code. Also, I'm using LV2009. Thanks
Solved! Go to Solution.
07-13-2010 04:18 PM - edited 07-13-2010 04:21 PM
You are queueing one value and then immediately after you are flushing the queue, which is now empty for the next loop iteration. You will never have more than one element in the queue at one time. So how can you expect to get an array greater than one element when you flush?
If you want to keep a running average, use a shift register to hold an array of data. Use Add Array Elements and divide by the Array Size. Or use the Mean function.
07-13-2010 05:00 PM
Ok thanks. I was using Flush to get the data into an array for summation, but I guess I just overlooked the fact that it actually flushed the data in the queue with each iteration. I feel a bit like a fool, but I do appreciate the feedback, tbob.
I was thinking the queue method would be more efficient than the shift register/array method, but I suppose if it doesn't work, that's not very efficient...
Thanks again.
07-13-2010 05:04 PM
Instead of a flush, you can use Get Queue Status to get the elements without deleting them.