LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

how to insert numbers at the end of an array

I am trying to make an array with incoming numbers in an if statement.  I have a counter to tell where to place the number in the array but it always overwrites the fist index in the array.  Is there a way to append numbers to an array inside a loop?  (by the way i tried almost everything in the array palette).
 
Dustin
0 Kudos
Message 1 of 3
(2,682 Views)
Dustin,

Initialize the array to a size equal to or larger than the maximum size of the final array. Pass it into a loop via a shift register. Inside the loop use Replace Array Subset with the new element and the appropriate index(es). If no data is available on a particular iteration, use a case structure to bypass the Replace Array Subset function.

By pre-initializing the array you avoid memory re-allocations as the array grows. For samm array it is not a big issue but for larger array this can be a significant advantage.

Lynn
0 Kudos
Message 2 of 3
(2,666 Views)
While pre-inizializing the full array and replacing elemets as you go has performance advantages if the arrays get big, the answer to your specific question is as follows:
 
There are two easy ways to append an array element to the end of an existing 1D array, thus growing the array by one.
  1. Use built array (preferred!)
  2. Use "insert array element" with the index terminal disconnected.

Message Edited by altenbach on 08-01-2006 09:23 AM

Message 3 of 3
(2,651 Views)