LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

create an array of consecutive integers

What is the best way to create an array of consecutive integers of a given length?

For example, if I want a 1-D array of the first 1000 integers, I usually wire 1000 to a For Loop and wire the loop's counter to an external array using auto-indexing. While this is simple to implement, is there a better or faster way to generate my array, especially for large arrays? I am using Labview 5.1.

Thank you,
Scot
0 Kudos
Message 1 of 4
(16,852 Views)
I think what you do is as efficient as it can get. There is no built in function which initializes an array to anything else than a constant value, so if you want an array with values equal to the index of the array element this really is the best solution.

Rolf K
Rolf Kalbermatter  My Blog
DEMO, Electronic and Mechanical Support department, room 36.LB00.390
Message 2 of 4
(16,852 Views)
If you define the array space outside of the loop, using the Initialize Array function, wired for the desired number of elements, then use the Replace Array Subset function to replace each element as you index through the array, it should initialize a lot faster, especially for a large array. As I understand it, using the loop to build the array (effectively what you're doing) requires copying the old array to a new array with one additional element, every time through the loop. The replacement mechanism just updates a value in an allocation that's already been created and initialized. So you avoid large memory allocation tasks and large amounts of copying of data from the old array to the new one.

Hope that helps. Sorry this a very 'late' r
eply - other work has kept me away too long!

Bob
0 Kudos
Message 3 of 4
(16,852 Views)
Not really. With a for loop, the LabVIEW compiler preallocates an array sized to the number wired to the Loop Count so there is no copying of data or resizing of the array. Howver, this can happen with a while loop and the build array function or autoindexing because there's no way to know ahead of time how large the array is supposed to be.
0 Kudos
Message 4 of 4
(16,852 Views)