LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Building array with n elements

Hi,

Does any one know how to specify the size of an array without doing it manually (by resizing the array)?

I want to specify the size of the array and get an array of that size.

Thanks,

Samah


0 Kudos
Message 1 of 6
(4,483 Views)

I'm not sure from your post if you're talking about the array's actual data or its appearance on the front panel.  If you're talking about the data, you can use the "Initialize Array" function in the Array subpalette.  If you're talking about the front panel, you can change the number of visible objects in an array by enlarging it via its border, but that doesn't affect the actual size of the data in terms of the number of elements.

If this answer doesn't help you, please explain your problem in more detail...it's especially helpful if you attach a VI illustrating the problem you're having.

Good luck,

-D

0 Kudos
Message 2 of 6
(4,483 Views)
Hi Darren,

What I need is to build an array of size 100. I want to specify the size of the array without me draging the array in the fort panel to adjust the size.

Thanks,

Samah


0 Kudos
Message 3 of 6
(4,479 Views)
I believe you are doing some confusion here with other programming languages : in LabVIEW, arrays are dynamic. That is to say there is no need to declare the size of an array : the size will be set automatically the first time you use the array, and modified automatically by subsequent operations. And you don't need to stretch an array indicator to create the corresponding elements.

So, just wire it and use it !

The only exception is when manipulating large arrays, because frequent changes in array size will be time consumming since LV as to re(-de)allocate memory. There, an array should be created at once with a size corresponding to its max size (using bthe function described by Darren...) and elements replaced according to operation results.
Chilly Charly    (aka CC)
0 Kudos
Message 4 of 6
(4,473 Views)

Hi samah,

To add slightly to what CC said, let's say you want an array of 100 random numbers.  To do this in LabVIEW, you would drop the Random Number function inside a For Loop, and wire that function to the For Loop's border.  Then you would create an indicator off the output tunnel of the For Loop that you just created.  Voila...an array of 100 random numbers.  Notice this didn't involve sizing anything on the front panel.

Check out the on-line help in LabVIEW on arrays for more information, and there are also some examples involving the manipulation of arrays in your [LabVIEW]\examples\general folder...in particular, arrays.llb has some good examples.

Hope this helps,

-D

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


Thanks D and CC 🙂 I got it.

0 Kudos
Message 6 of 6
(4,464 Views)