LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Preallocate array use amount needed and delete excess

Hello, simple question which I saw somewhere on the net but can seem to relocate it.

So I have a loop that inserts an element into a large 3D array every iteration of the loop. Unfortunately, because the loop stops based of a unpreditable variable I do not know how many times this loop will run. As a result I do not know how large my 3D array needs to be. As of now I initialize a 3D array that is bigger than needed and insert elements in. The problem is how do I delete the unused or extra elements within the array that were not needed.

Thanks,
Taylor S. Amarel

Learning is living.
Co-Founder and CEO of http://3dprintingmodel.com/

"If we did all the things we are capable of, we would literally astound ourselves."
-Thomas Edison
0 Kudos
Message 1 of 6
(2,587 Views)

ummmm the "delete from array" primative on the array palatte would be one way to trySmiley Wink


"Should be" isn't "Is" -Jay
0 Kudos
Message 2 of 6
(2,580 Views)

Use "Array subset" to get the valid portion.

0 Kudos
Message 3 of 6
(2,576 Views)

Reshape array is also commonly used for this purpose.

0 Kudos
Message 4 of 6
(2,564 Views)

@nathand wrote:

Reshape array is also commonly used for this purpose.


For higher dimension arrays (3D in this case), this will only work if the elements are arranged in the correct order. This is not guaranteed per se, but can always be arranged if programmed correctly.

Message 5 of 6
(2,555 Views)

If you are preallocating an array, then you don't want to insert elements into it.  That will just make a big array grow larger.

 

I hope you meant you were replacing elements of that preallocated array.

0 Kudos
Message 6 of 6
(2,538 Views)