LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Keeping Unique 1D Size in 2D array

Is there a way to force Labview to maintain the original array dimension independently from one another when creating 2D or even possibly 3D arrays?  It appears to be autosized every set of inputs to the maximum size.  But I want to maintain each set of array size independent from one another.  How do I do that?

 

 

1.jpg

0 Kudos
Message 1 of 14
(4,279 Views)
Cant be done. Initialise your arrays with an impossible number or string and use to determine original size (filter) when you want to use 1D.
0 Kudos
Message 2 of 14
(4,266 Views)
Actually, another method is to trick into a cluster but that requires a few more curves.  I'd prefer this method if possible because it saves a few steps in execution.
0 Kudos
Message 3 of 14
(4,262 Views)
Like I said.  Initialise your 2D array with a number such as 99 (shouldn't correspond to valid data).  You should insert you 1D array using Replace Array Subset VI.  When you want your 1D array back, index it and filter out 99 to get 1D array of original size.
0 Kudos
Message 4 of 14
(4,248 Views)

Another commonly used device is to make the first (0th) element of each array represent the array length:  so new array A would be

 

0x06 (6 elements follow)

0x01

0xFF

etc. 

 

then when you're working one of the 1d arrays, you index the 0th element, convert it to I32 and use that as the length in a subarray node to return just the original array. 

-Barrett
CLD
Message 5 of 14
(4,229 Views)

Be aware that such an approach has issues with memory use.  If your data sizes are big enough, you should use the cluster approach.  For those who do not know what this is, consider the following:

 

 2DArraysAndArraysOfClusters.png

 

In the bottom image, each array element is composed of a cluster containing a 1D array.  This allows each 1D array to be independently sized, but also adds an extra layer to getting data out of the 1D array.  This can cause issues with data copies in older versions of LabVIEW, but the In Place Element Structure has largely eliminated these for newer versions.

Message 6 of 14
(4,193 Views)
Nice one Doc.  Just to clarify, can you show BD implementation using controls and not constants.
0 Kudos
Message 7 of 14
(4,174 Views)

Sure.  Here is a screenshot showing buffer allocations.  Note the extra copy of the cluster using the traditional extraction of a single element from the array of clusters of arrays.  It is not there if using the In Place Element.  Code is is LabVIEW 8.5 (when the In Place Element was introduced).

 

Accessing1DArrayofClustersOfArraysWithBufferAllocations.png

 

Note that in LabVIEW 2009, the buffer viewer will show a buffer on the output of the index array in the In Place Element.  This buffer is not a full copy, but a static allocation to handle indexing an out-of-bounds element.

Message Edited by DFGray on 04-06-2010 08:38 AM
Message 8 of 14
(4,144 Views)

That made sense to me after the 5th time I read it.  Now I know about In Place Element Structure.  I was using LV8.0 for too long;-)

 

https://www.ni.com/docs/en-US/bundle/labview/page/in-place-element-structures-increasing-memory-effi...

 

Is the In Place Element Structure you recommend we implement all the time (when we can)?  Can you give examples?  Has anybody done any benchmarking?

0 Kudos
Message 9 of 14
(4,126 Views)
You can use "Delete from Array" function to delete the values "00" before giving it to your final output/indicator. Search for 0 and delete the values from the index found by Search Array function
Message Edited by Fragger Fox on 04-07-2010 10:15 AM
-FraggerFox!
Certified LabVIEW Architect, Certified TestStand Developer
"What you think today is what you live tomorrow"
0 Kudos
Message 10 of 14
(4,123 Views)