LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how do I update the array and take the most recent elements only?

 

 

I am a little confused about this WHILE loop. 

 

The intention is to overwrite the elements of the initial array with a value from within the WHILE Loop and pass that new array to the SHIFT REGISTER each time the WHILE loop executes.  So, my intention is that the WHILE loop should replace the initial values of the array with the constant value (12) inside the WHILE loop.  In other words, the initial array is 10, 10, 10, 10.  After 4 iterations, why isn't it 12, 12, 12, 12???   And, then, the slope would read "0" because the elements would be the same. What am I missing with the execution of these functions???

 

Ultimately, I want to overwrite an array that is only 4 values long, one value at a time; one element overwritten per WHILE loop execution, and I have really got myself lost here.

 

Thanks.

0 Kudos
Message 1 of 3
(2,452 Views)

A couple of things are screwed up.

 

Since you appending at the end, you need to take the subset of 3 elements starting at position 1,

After appending the new value, the array is back at four elements.

The last element of an array with 4 elements has index 3.

 

See attached correction.

 

It is easier to troubleshoot things like that if you would place array indicators at the various locations. You also need a small wait.

 

(Of course you should find a better algorithm that operates "in place". It is inefficient to constantly shrink and grow an array in a loop. Try it!)

Message 2 of 3
(2,449 Views)

Ah ha, I think I see how you did  that.  So, what I was TRYING (and failing) to do was to capture all 4 elements, and over-write the 4th element.  I think what you are doing is capturing the last 3 of the original 4 elements, and appending the fourth.  Am I understanding that correctly?

 

Thanks a lot, by the way.  This gets me going to more important aspects of my development!

 

Dav

0 Kudos
Message 3 of 3
(2,422 Views)