LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

initialize linear array

What is the most efficient way to initialize an array of constant increment? I want to quickly build an array with the starting element value, increment, and number of elements all passed in to it. I know I could start with an empty array and keep resizing it and adding element in a for loop. But was told that resizing is not very efficient. Somehow I could use replace array subset. But how do you do that?

Thanks.
0 Kudos
Message 1 of 7
(6,762 Views)
Cheers
Matthew Fitzsimons

Certified LabVIEW Architect
LabVIEW 6.1 ... 2013, LVOOP, GOOP, TestStand, DAQ, and Vison
0 Kudos
Message 2 of 7
(6,756 Views)
Use the VI "Ramp Pattern.vi"


LabVIEW, C'est LabVIEW

Message 3 of 7
(6,753 Views)

Why would you need any "array resizing"? Just use autoindexing. Since N is known from the beginning, LabVIEW can efficiently allocate the output array.

The Ramp pattern that JP mentioned is not available in "LabVIEW base" and the inputs are a bit different than your requirement (N, start, end). It is trivial to cook your own with a few strokes of the mouse. Attached is one example. (LabVIEW 7.0)

Message Edited by altenbach on 05-06-2006 11:10 AM

Download All
Message 4 of 7
(6,748 Views)
Thank you all very much! Smiley Happy
0 Kudos
Message 5 of 7
(6,706 Views)

thank you for the information but if i need to add upper limit how can you do that

0 Kudos
Message 6 of 7
(5,868 Views)

@habeb1987 wrote:

thank you for the information but if i need to add upper limit how can you do that


This thread has not seen activity for 8 years, so the information might be a bit stale.

What do you mean by "upper limit"? Do you (1) want a specific endpoint or (2) do you want to coerce the final ramp to an upper limit where it becomes horizontal instead of increasing?

 

 

Solution for (1): Have you tried ramp pattern? the "by samples" needs [start, end, N]. "end" is your upper limit?

Solution for (2): add an "In range and coerce" function to the ramp. (words for arrays, limits can still be scalar)

0 Kudos
Message 7 of 7
(5,854 Views)