02-25-2013 02:46 PM
Hi,
I'm completely new to labVIEW as a student. I have this question for overwriting an array after it reaches a specified index.
In specific, I have to add numbers to an array continuously and take the average of the last three values.
I wanted to make a new array, which only stores three numbers and after that, starts overwriting the first one, then the second, the third, te first, the second,... .
Can someone help me, showing me how to trim my arrays to a limit of 3 values?
Thanks in advance!
(Sorry for bad english)
Solved! Go to Solution.
02-25-2013 02:50 PM
Take a look at split array and replace array. You can search for both in the examples that ship with LabVIEW.
02-25-2013 02:53 PM - edited 02-25-2013 02:54 PM
What you are referring to is called a circular buffer. Probably the easiest way is to use the Replace Array Subset and the Rotate 1D Array with a shift register. My preferred way is to use a lossy queue.
02-25-2013 03:41 PM
Is this also possible in a while loop? Also I can't find a terminal to input my data source
Here's a picture of where it should be placed in.
02-25-2013 03:50 PM
Yes, you can also implement a circular buffer in a while loop. Right click on the edge to add a shift register.
02-25-2013 03:59 PM - edited 02-25-2013 04:02 PM
To take the mean, the order in the array does not matter. Here's what I would do.
(With a little more code, it will also work for the first two iterations. See this old post)
There is also mean ptbypt, which does the same thing!
02-25-2013 04:07 PM
I'll try this one in an instant, thanks!
still, what's wrong in this scheme?
02-25-2013 04:29 PM - edited 02-25-2013 04:45 PM
@DonVito wrote:
I'll try this one in an instant, thanks!
still, what's wrong in this scheme?
This will not work because of dataflow and because it makes no sense at all.
First, your while loop on the left runs for a long time, generating an evergrowing array at the right boundary until stop is pressed. The loop on the right needs to wait because it's data depends on the first loop.
Once the first loop stops, it calculates the mean of all N elements. At the same time, the second loop starts, replacing the first element with the iteration count and rotating the potentially very large array. This has nothing to do with the problem as posed. This will happen very fast, so after a very short time (nanoseconds), the array will be filled with very large values...
Only after the second stop is pressed, the mean of this new array (containing only integers) will be taken. The result will be random.
Have you tried my code?
02-26-2013 03:38 AM
Ok, I understand! 😄 I'll try your code later this day