From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keep appending arrays in while loop

Hi all,

 

I have a very simple question. If I get data from a while loop. (1 point each loop, e.g. 11, 12, 11, 12, 23 at the first 5 loops). How can I make an array of this? I always get one data at the first loop.

0 Kudos
Message 1 of 6
(5,384 Views)

Use a shift register initialized with a 1D array and use build array to append the scalar.

0 Kudos
Message 2 of 6
(5,378 Views)
There are a couple of simple ways but they are not perfect. You can use a shift register and the build array function. Or, on the exit tunnel, you can right click and enable indexing, just like what happens with a for loop. Performance problems arise when you run for an extended period since the final array size cannot be determined and memory keeps needing to be reallocated. How long will the loop run and what delay between iterations?
0 Kudos
Message 3 of 6
(5,369 Views)

Hi,

 

Here is the code for solutions suggested by Christian and Dennis.

In Dennis's solution you will get array after stoping while loop. But in Christian solution you are able to see array if while loop in tunning also.Solution1.png

Solution2.png

0 Kudos
Message 4 of 6
(5,342 Views)

The solutions posted work, but again realize that if you run for a long time memory will continue to increase.  You do not have unlimited resources and building an array of an unbounded size will result is no available memory eventually.

 

It would be best to make sure the array size doesn't grow beyond some value.  If you use the build array method you can look at array size, and if it is greater than some value, perform an array subset and get the last X number of points.  That is unless you truely need all values at which point you would need to think about File I/O or other methods of temporarily storing the array.  Of course if you know your while loop won't run more than some value you probably don't need to worry about it.

0 Kudos
Message 5 of 6
(5,292 Views)

@Hooovahh wrote:

The solutions posted work, but again realize that if you run for a long time memory will continue to increase.  You do not have unlimited resources and building an array of an unbounded size will result is no available memory eventually.

 

It would be best to make sure the array size doesn't grow beyond some value.  If you use the build array method you can look at array size, and if it is greater than some value, perform an array subset and get the last X number of points.  That is unless you truely need all values at which point you would need to think about File I/O or other methods of temporarily storing the array.  Of course if you know your while loop won't run more than some value you probably don't need to worry about it.


Another method to go along with Hooovahh's concept here is to preallocate an array and store it in the shift register.  You then use Replace Array Subset to update the array.  You just need to keep track of which element to replace.  This avoids the whole reallocation of memory each time you add another element to the array.


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
0 Kudos
Message 6 of 6
(5,281 Views)