LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I make an array of unknown size?

I am creating an array of elements from a nested for-loop... thus there is no determined size. How can accomplish this?
0 Kudos
Message 1 of 10
(5,732 Views)
I'm not sure I understand your problem. A for loop will automatically create an array and you don't have to preallocate anything. This is assuming you're using the autoindex feature of a for loop. That's the fastest and most effecient way to create an array. If you're not doing this, could you explain exactly how you're creating the array?
0 Kudos
Message 2 of 10
(5,732 Views)
Use Build Array.vi and shift register(s) to dynamically create the array. See the attached.

For memory management, it is better to initialize the array and replace elements. If it's nested for loops, why don't you know the number of iterations?

Tim
0 Kudos
Message 3 of 10
(5,732 Views)
Dennis is correct, my original example was unnecessarily complicated (D'oh!). The for loop does all the work for you.
0 Kudos
Message 4 of 10
(5,732 Views)
You don't have to create an array before, just add new elements to a blank
array f size 0. Basically get size of array (which will start from 0) and
use that value for index in InsertArray function.


vishi

"gwong" wrote in message
news:5065000000080000003B920000-1042324653000@exchange.ni.com...
> I am creating an array of elements from a nested for-loop... thus
> there is no determined size. How can accomplish this?
0 Kudos
Message 5 of 10
(5,732 Views)
My for-loop will have multiple outputs and thus the array is of unknown size. I am attaching what I have so far and the problem lies in the building array. My program is supposed to be generating a square spiral shape on an XY graph. (The N-value for the outer most for-loop is just for testing purposes and will be changed.)
0 Kudos
Message 6 of 10
(5,732 Views)
Maybe you could explain exactly what you're trying to generate. The VI is hard for me to understand because you've wires going underneath objects and looping back and I would think your problem would be simpler to implement without all of the shift registers and just let the for loops generate arrays like they're intended.
0 Kudos
Message 7 of 10
(5,732 Views)
I think the easiest way is to attached the C code that I wrote and am trying to put into Labview. The problems I am running into are the variable k and also the setting of each array. Thanks for your help so far and any further help would be greatly appreciated!
0 Kudos
Message 8 of 10
(5,732 Views)
"gwong" wrote in message
news:50650000000500000041040100-1042324653000@exchange.ni.com...
> I think the easiest way is to attached the C code that I wrote and am
> trying to put into Labview. The problems I am running into are the
> variable k and also the setting of each array. Thanks for your help
> so far and any further help would be greatly appreciated!

What Dennis said is the easiest and best way to do that. To add C code to a
labview program for functionality already present in Labview makes no sense,
it adds unnecessary complexity and makes debugging much more difficult.
0 Kudos
Message 9 of 10
(5,732 Views)
Thanks I figured out my problem.
0 Kudos
Message 10 of 10
(5,732 Views)