LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Darren's Occasional Nugget 05/09/2012

When I first learned LabVIEW over 13 years ago, one of the things that stuck with me from my LabVIEW Basics course was that LabVIEW does not support creating an array of arrays:

 

nestedarray.png

 

One way that developers have tried to combat this limitation over the years is to create a 2D array of the appropriate data type, then keep a separate array indicating the column index of the last "real" data value within each row of the array:

 

2darray.png

 

This method works, but requires storing lots of garbage data that you don't need, and it also requires maintaining the separate index array, which can be a headache if you are frequently manipulating the contents of the array.

 

The best trick I know of for storing arrays of arrays is to stick an extra cluster in there, like this:

 

arrayclusterarray.png

 

This technique effectively allows us to store arrays of different lengths within an array.  No more garbage data, and no extra work required to keep track of how many values are in each array.  I have used this technique many times over the years when I need 'array of array' functionality in LabVIEW.  When you are generating the 'array of arrays' on the diagram, you can do so with a Bundle function to add the extra cluster, and likewise use an Unbundle when you need to retrieve one of the nested arrays:

 

arrayarraydiagram.png

 

P.S. - My motivation for posting this nugget is this post on the 'Eureka' thread, in which Ben admirably admits to just now learning the 'array of arrays' trick that I've taken for granted for years.

Message 1 of 15
(16,717 Views)

I'm still the idea that this is a cute trick that LV could maybe do FOR us ( as a separate daty type to a normal 2D array but I understand the added complexity for (perhaps) small benefit makes it unlikely.

 

I've been using this trick often.  It helps me keep track of the "Rows" and "Columns" much more easily also.... I'm not able to think in terms of 2D arrays properly, I'm always a transpose away from success....

 

Also kudos to Ben....

 

Shane.

0 Kudos
Message 2 of 15
(16,691 Views)

Thanks for the Nugget Darren.

 

... and for those reading along before you implement the array of cluster where you are dealing with large data sets be sure to read Rolf's additional comments here about performance and the trade-offs;

 

"easy to read" vs "fast".

 

Which of course reminds me a Sea-story errr  I mean comic from G-Wiz.

 

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 3 of 15
(16,673 Views)

@Ben wrote:

Thanks for the Nugget Darren.

 

... and for those reading along before you implement the array of cluster where you are dealing with large data sets be sure to read Rolf's additional comments here about performance and the trade-offs;

 

Ben


Where?


"Should be" isn't "Is" -Jay
0 Kudos
Message 4 of 15
(16,632 Views)

Darren,

 

Thank you.  I was aware of the array of cluster of array although I rarely use it.  I actually have an application coming soon where this may be useful.

 

I was going to ask about performance with large arrays unitl I saw Ben's mention of Rolf's comments.  So I will wait for Ben to unhide the link and read that first.

 

Lynn

0 Kudos
Message 5 of 15
(16,620 Views)

@Jeff Bohrer wrote:

@Ben wrote:

Thanks for the Nugget Darren.

 

... and for those reading along before you implement the array of cluster where you are dealing with large data sets be sure to read Rolf's additional comments here about performance and the trade-offs;

 

Ben


Ah- a little digging and three jumps back


 


"Should be" isn't "Is" -Jay
0 Kudos
Message 6 of 15
(16,593 Views)

Goodness gracious, those Silver Controls certainly chew up the real estate don't they?  They are the FP equivalent of the terminal icon view IMO.  Here is what the data structure could look like using (1) My totally hackified borderless cluster which lets me invisibly bundle controls on the FP (2) the usual system controls in modern containers.

 

ArrayOfClusterOfArray.png

 

I have attached the custom cluster I use, but since I did this via black magic and reverse engineering, caveat bundler.  In other words, you have been warned.  No substitute for simple, clean controls.

Message 7 of 15
(16,578 Views)

I used this trick a couple of years ago for some XPT drivers.  My main peeve with the cluster of arrays is that it is not scalable.  But for the situation, it worked perfectly.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 8 of 15
(16,508 Views)

Edit:  I just realized I misread your implementation.  Oh well, another option to put in my tool belt.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 15
(16,488 Views)

Sorry.

 

reply # 12 in this thread is where Rolf posted.

 

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 10 of 15
(16,403 Views)