05-09-2012 01:43 PM
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:
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:
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:
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:
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.
05-09-2012 02:03 PM
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.
05-09-2012 02:12 PM
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
05-09-2012 03:05 PM
@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?
05-09-2012 03:14 PM
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
05-09-2012 03:38 PM
@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
05-09-2012 03:52 PM
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.
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.
05-09-2012 07:56 PM
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.
05-09-2012 08:59 PM
Edit: I just realized I misread your implementation. Oh well, another option to put in my tool belt.
05-10-2012 07:13 AM
Sorry.
reply # 12 in this thread is where Rolf posted.
Ben