LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Limiting Array Size

I have continuous running data that I want inserted into a 10 element array for analysis on last 10 data points. I can't figure out a way to limit an array size. I've tried the Initializing Array with dimension size set to 10. I've also tried a Property Node set to 10 columns and 1 row. I am currently using a Build Array with Feedback Node which seems to be working to insert the data.
0 Kudos
Message 1 of 5
(6,145 Views)
You're almost there.

Instead using the Build Array function, use the Replace Array Subset function always insterting at element 0. But before you replace the element, us ethe Rotate 1D Array function with a 1 on the n terminal. This will rotate the last element in the array (the oldest one) to the 0 index where it will then be replaced by the Replace Array Subset function, so you will have the 10 latest elements and your array will always be 10 elements in size.

The attached image shows how to set this up.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 2 of 5
(6,145 Views)
Forgot to mention, the Build Array function will always add more elements to the array, even if you initialize it first. So if you initialize a 10 element array, then use the Build Array function on it, the array will be 11 elements in size.

This has preformance and memory management issues and should be avoided in loops.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 3 of 5
(6,145 Views)
One way to do it would be to add a shift register to your loop and extend it on the left-hand side to have 10 elements. This way, the last 10 elements will always be present. This takes up quite a lot of space however.

Another option is using a cluster to hold the data as this is then limited in size. You'll need to uncluster and re-cluster to maintain order, but you'll definitely be limited to your 10 elements this way.

Yet another possibility is to simply check the size of your array after appending and snip the array size back to 10 if it grows larger than 10. From a memory-management point of view this is quite crude.

My final offering is using apre-initialised 10-unit array, and each time before using "Replace aray element" to the last posision
(index 9) rotate the array by 1 (found under the Array tools).

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
0 Kudos
Message 4 of 5
(6,145 Views)
Sivart,
I believe the attached vi may contain a solution (or two) to your problem. There are two examples, both which record all of the continuous running data (through a random number generator) while providing an array indicator with the 10 most recent data points.

If I am interpreting your question correctly, I believe what you want to do is perform some type of analysis or plotting on only the 10 most recent data points collected - the two methods for doing this in the attached vi allow you to access these points through a "Last 10" array indicator, which you could then wire to a waveform graph or any other number of functions. I have encountered this issue a number of times during my limited L/V programming experience and have found the attached
algorithms to be of some use.

The first example utilizes the "Quotient & Remainder" vi, which is located on the numeric palette. When the remainder of the while loop iteration divided by 10 equals 0, the 10 data point array is stored in the "Last 10" indicator and then reinitialized back to an empty state to collect another 10 points. Once 10 more data points are collected, the "Last 10" indicator is updated with these values.

The second example, instead of updating all 10 values at one time, will update the array continuously with each while loop (or for loop) iteration. This just uses the "Replace Array Subset" vi which is located in the Array pallete.

Hope this helps!
Message 5 of 5
(6,145 Views)