LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How do I convert a Cluster of Clusters to a single Cluster of elements?

This is a simplified version of what I'm trying to do - fixing this saves a lot of work in my code.

I have created two clusters with two bundle functions, the first with four elements and the second with 8 elements. I bundle them together, and the output is then a "cluster of two clusters". (the first cluster having four elements, and the second having 8 elements)

Is there a tool that will change that "cluster of clusters" to a cluster of 12 elements?

Thanks,
Mike
0 Kudos
Message 1 of 7
(3,718 Views)
Yes, create a subVI containing code similar to the one shown inside the black square of the attached image.

Input: cluster of clusters, output: single cluster.
Message 2 of 7
(3,710 Views)
Thanks for the suggestion.

As I said before, I was providing a simplified example. In the real application, the size of the clusters changes, so one vi won't solve the problem in all instances. I guess I'll have to write several vi's.

I was looking for a magic tool that would flatten any cluster of clusters to a single cluster - but I guess NI hasn't written that one yet.

Thanks again,
Mike
0 Kudos
Message 3 of 7
(3,672 Views)
The solution attached in the picture can also be used. Provided that the target cluster has all the elements of the source clusters in the same order and representation, it will work. This solution doesn't provide edit time error if the clusters don't match. A run-time error might be detected when the data can't be unflatten into the target cluster but it is not guaranteed.


LabVIEW, C'est LabVIEW

Message 4 of 7
(3,655 Views)
Hi Guys!

Both Altenbach and Jean-Pierre's solutions are the best methods for doing this. You are right, wd8ivl, in saying that both of these methods force you to hard-code the type of the final data type. But you're going to need to do this anyway to use the resulting data!

Good luck!

Travis H.
National Instruments
Travis H.
LabVIEW R&D
National Instruments
Message 5 of 7
(3,599 Views)
Hi wd8ivl,

I agree with all prior posting re: the Q as posted.

The attached zip has a LV 6.1 example along with a jpg illustrating two methods that could be used if we take a step back and loosen some restrictions.

Both methods build the cluster using "bundle by name".

The first just insert the sub-sets of data into a 12 element cluster in two steps. This has the drawback of possibly dragging unrelated data around when it is not needed.

The second uses type defs that avoid the "extra data copies" and picks-up the luxury of the sub-VI used to combind the data will automatically adapt when the cluster definition changes. This method does not give you a flat cluster in the end. It also requires you have a unique sub-VI for each cluster type.

Like I said, it may not with what you are attempting, but these methods could be helpful for similar situations.

Ben
Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
0 Kudos
Message 6 of 7
(3,567 Views)
Ben,

Thanks for the examples.

I'm going ahead with the first method, as the data I'm dragging around isn't unrelated - it's stuff I actually need.

Thanks again for your help,

Mike
0 Kudos
Message 7 of 7
(3,532 Views)