LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I append to an array of defined length and have the first value added be the first value out.

Solved!
Go to solution

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 

0 Kudos
Message 1 of 10
(3,944 Views)

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

0 Kudos
Message 3 of 10
(3,938 Views)

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.

0 Kudos
Message 4 of 10
(3,910 Views)

Also I'm using LV7 so I couldn't open your attachments.

 

S

0 Kudos
Message 5 of 10
(3,908 Views)
Solution
Accepted by topic author ssmith490D

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

Message Edited by Sima on 01-13-2009 06:14 PM
Download All
Message 6 of 10
(3,888 Views)
I just realized I should have combined the case selector with the case structure, but you can do that if you find the functionality is there 🙂
0 Kudos
Message 7 of 10
(3,864 Views)

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.

Regards,

Jon S.
National Instruments
LabVIEW NXG Product Owner
Message 8 of 10
(3,852 Views)

Sima--

       Thanks a lot. It works fine.

 

S

0 Kudos
Message 9 of 10
(3,834 Views)

Jon--

    Thanks for converting it.

 

S

0 Kudos
Message 10 of 10
(3,833 Views)