NI Home > Community > NI Discussion Forums

LabVIEW

Showing results for 
Search instead for 
Do you mean 
Reply
Trusted Enthusiast
Darren
Posts: 2,872

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.

Darren Nattinger, CLA
LabVIEW Artisan and Nugget Penman
Trusted Enthusiast
Intaris
Posts: 3,196
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

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.

Knight of NI
Knight of NI
Ben
Posts: 16,143
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

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

Ben Rayner
Who is NOT John Galt... yet... just building Rayner's Ridge
Scheduled to close on the new ridge next week!
Proven Zealot
Jeff·Þ·Bohrer
Posts: 7,825
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012


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?

8-Ball Consulting advertising banner

Certified LabVIEW Consultant. The partner you can bank on when you're behind the 8-Ball.
Knight of NI
johnsold
Posts: 10,056
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

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

Proven Zealot
Jeff·Þ·Bohrer
Posts: 7,825
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012


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


 

8-Ball Consulting advertising banner

Certified LabVIEW Consultant. The partner you can bank on when you're behind the 8-Ball.
Trusted Enthusiast
Darin.K
Posts: 3,880

Re: Darren's Occasional Nugget 05/09/2012

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.

Proven Zealot
crossrulz
Posts: 8,605
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

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.



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Proven Zealot
crossrulz
Posts: 8,605
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

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



There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Knight of NI
Knight of NI
Ben
Posts: 16,143
0 Kudos

Re: Darren's Occasional Nugget 05/09/2012

Sorry.

 

reply # 12 in this thread is where Rolf posted.

 

Ben

Ben Rayner
Who is NOT John Galt... yet... just building Rayner's Ridge
Scheduled to close on the new ridge next week!