01-13-2009 10:36 AM
I want to build/append to an array. Let's say the length is defined at 10 elements. When the 11th element comes in I want the first element to be kicked out so that the array always has the most recent 10 elements in it in order. the arrays should look like this:
{0,1,2,3,4,5,6,7,8,9}
{1,2,3,4,5,6,7,8,9,10}
{2,3,4,5,6,7,8,9,10,11}
etc.
Any help is greatly appreciated. Thanks
Solved! Go to Solution.
01-13-2009 10:53 AM
Like this?
01-13-2009 11:00 AM
I would first use the Rotate Array function, wired with a -1 value, which causes it to shift everything over to the left and take the leftmost value and move it over to the rightmost slot (ie rotating everything to the left)... then use Replace array Subset to replace the last value in your array (the rightmost value)... it woudl do this
1 2 3 4 5 6 7 (ROTATE) 2 3 4 5 6 7 1 (REPLACE WITH NEW NUMBER 😎 2 3 4 5 6 7 8
see attached VI, basically what your asking for is called a FIFO
01-13-2009 01:25 PM
Monse--
This works fine after the array is filled. Before that the new element is placed in the 0 spot and the previous element is move to the end of the array. Like this:
{1,n,n,n,n}
{2,n,n,n,1}
{3,n,n,1,2}
I want this:
{1,n,n,n,n}
{1,2,n,n,n}
{1,2,3.n.n}...
{2,3,4,5,6}
{3,4,5,6,7}
{4,5,6,7,8}
Thanks for the help.
01-13-2009 01:27 PM
Also I'm using LV7 so I couldn't open your attachments.
S
01-13-2009 05:12 PM - edited 01-13-2009 05:14 PM
Here's a revised VI, except I'm using LV8.5 and the lowest I can save down to is 8 so perhaps someone will be kind enough to convert this?
Attached an image too
01-14-2009 11:22 AM
01-14-2009 04:56 PM
ssmith490D,
I looked at the program. It looks like it is what you want. I saved it for version 7.0 if you already haven't built it from the picture.
01-15-2009 08:07 AM
Sima--
Thanks a lot. It works fine.
S
01-15-2009 08:07 AM
Jon--
Thanks for converting it.
S