LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Overwriting array after specified index

Solved!
Go to solution

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)

 

0 Kudos
Message 1 of 9
(4,125 Views)

Take a look at split array and replace array. You can search for both in the examples that ship with LabVIEW.



Mark Yedinak
Certified LabVIEW Architect
LabVIEW Champion

"Does anyone know where the love of God goes when the waves turn the minutes to hours?"
Wreck of the Edmund Fitzgerald - Gordon Lightfoot
Message 2 of 9
(4,122 Views)

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.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 3 of 9
(4,119 Views)

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.

 

 

0 Kudos
Message 4 of 9
(4,106 Views)

Yes, you can also implement a circular buffer in a while loop. Right click on the edge to add a shift register.

 

>

"There is a God shaped vacuum in the heart of every man which cannot be filled by any created thing, but only by God, the Creator, made known through Jesus." - Blaise Pascal
0 Kudos
Message 5 of 9
(4,093 Views)
Solution
Accepted by topic author DonVito

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!

 

 

Message 6 of 9
(4,078 Views)

I'll try this one in an instant, thanks!

 

still, what's wrong in this scheme?

Capture.PNG

0 Kudos
Message 7 of 9
(4,070 Views)

@DonVito wrote:

I'll try this one in an instant, thanks!

 

still, what's wrong in this scheme?

Capture.PNG


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?

 

 

 

Message 8 of 9
(4,060 Views)

Ok, I understand! 😄 I'll try your code later this day

0 Kudos
Message 9 of 9
(4,028 Views)