LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Easier way to convert array to cluster with named variables?

Solved!
Go to solution

I have an array of variables, I would like to essentially unbundle that array to named variables.

 

I believe the only way of doing this is by converting the array to cluster (besides removing each element one by one)?

 

Is what I have done below the best way of doing it? seems a bit weird having to unbundle and rebundle by name.

 

comments appreciated.

 

example array to cluster with name.png

 

 

0 Kudos
Message 1 of 14
(7,578 Views)

You can use the Array to Cluster node to do the conversion for you. The tricky part is the name matching. If the first element in your cluster is always going to be the first element in the array, it works fine. But as soon as you add a new cluster element, you will run in to trouble. The Bundle by Name eliminates this problem by using the names and is really the only way to make sure your names always match up with the right array element.

 

To clarify, you don't need the Bundle by Name to wire the bundle straight in to the indicator you have, but in order to get those names in the Unbundle by Name node, you do.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 2 of 14
(7,556 Views)

Also, you should make that cluster into a Typedef, for future expansion.

0 Kudos
Message 3 of 14
(7,548 Views)

Thanks for the reply.

 

The first array element will be the first cluster element, and the rest of the elements will be in the same order for each.

 

How can I use the array to cluster to add names to the cluster elements?

 

Is there a way to add names to the array elements?

0 Kudos
Message 4 of 14
(7,544 Views)

 

Your problem code is actually right before the red square. Instead of the "array-to-cluster-unbudle dance", you should simply use a plain index array resized for the same number of outputs. same functionality, less convoluted.

Your wiring is a bit of a mess and it is hard to tell if the order of elements in the array is the same as in the cluster.  Maybe a simple typecast to the cluster would work.

 

Message 5 of 14
(7,525 Views)

[Deleted]

 

Altenbach to the rescue!

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


0 Kudos
Message 6 of 14
(7,522 Views)

Here is what Altenbach means. This is what you want, right?
Array to Cluster.png

Edit: shoot you can even get rid of the Array To Cluster node in there and just type cast the array.

 

Make sure you Type Def your cluster so you can change those names in the future to keep your code consistent.

Cheers


--------,       Unofficial Forum Rules and Guidelines                                           ,--------

          '---   >The shortest distance between two nodes is a straight wire>   ---'


Message 7 of 14
(7,511 Views)
Solution
Accepted by topic author hydzik

@altenbach wrote:

Maybe a simple typecast to the cluster would work.


Of course it does!

 

 

Message 8 of 14
(7,509 Views)

Note that typecasting has no error checking, so you better make sure that the sizes and types match or you get garbage, of course.

0 Kudos
Message 9 of 14
(7,495 Views)

thank you all, this was what I was after.

0 Kudos
Message 10 of 14
(7,490 Views)