From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

array to cluster with adjustable cluster size

Hi all

Here I have  a dynamic 1D array and I need to convert it into cluster. So I use Array to Cluster function. But I notice that the cluster size is a fix value. How can I adjust the cluster size according to the 1D array size?
Anyone pls give advise..

Thanks....
0 Kudos
Message 1 of 27
(17,484 Views)

Hi ,

i am afraid that this cannnot be done dynamically on the run while ur program is running.

To cluster size according to the 1D array size, click on the array to cluster function, select cluster size option in dropdown menu and enter the size.

hope this helps

Regards

Dev

Message 2 of 27
(17,449 Views)
Hi

Ya, I know that I can change the cluster size in a dropdown menu manually....But can it be controlled? Let's say if I have value 5 then it passes 5 to the cluster size in the Array to Cluster function... Is this possible?
0 Kudos
Message 3 of 27
(17,430 Views)
Sory 222, this is not possible... you have to keep working on the array... what you can do (depending on your app) is to put the whole array in the cluster and then work with the array index ;).

We have two ears and one mouth so that we can listen twice as much as we speak.

Epictetus

Antoine Chalons

0 Kudos
Message 4 of 27
(17,431 Views)

Why do you want to dynamically control this?
There is no way to programmatically select a cluster element, so you would have to select it in advance, meaning that programmatically defining the cluster (even if it was possible) would not help you.

If you tell us what you actually want to accomplish, we could suggest another way to do this.


___________________
Try to take over the world!
Message 5 of 27
(17,423 Views)
Hi 222:

There is a trick you can use to adjust a "variant" cluster to an array size.

It's a bit hard for many items, but, anyway,

You can create a SubVI whith 1 input
i1.- The array you want to convert to cluster

and 1 output
o1.- A Variant with the converted cluster.

----
The subvi consists on a Case depending on the number of elements of i1. And inside the Case there is an ArrayToCluster function, with the correct ClusterSize value (this is the hard part)

The converted cluster must be converted to Variant, so the output of the Case is the same.
---
After the SubVI you can convert the variant to a cluster, if you have a cluster of the same number of elements as the array size.

This can be useful if you have data of the same type that can be treated as an array but you want to show it in a special way, not as an array.

First you have your cluster control with the data distributed in a special way, then you convert to an array, treat the data, pass it to the SubVi and then convert to the known cluster and update the cluster value.

Hope it helps,
Aitortxo.
Message 6 of 27
(17,428 Views)
Clusters are fixed size structures. Arrays are variable size structures. If you need an adjustable size structure, you need an array.
If you explain what you need to do, it will be simpler for us to help you than if you ask for an adjustable fixed size structure... Smiley Wink

Message Edité par Jean-Pierre Drolet le 02-27-2006 07:42 AM



LabVIEW, C'est LabVIEW

0 Kudos
Message 7 of 27
(17,422 Views)

Clusters are like structs in c/c++ they are static representations of a data structure, if you have different sized structures they are not the same structure.  You could make a few different cluster types (typedefs) and create a polymorphic function to take a 1d array and convert it to the approperate struct and return this or you can have a polymorphic vi which takes a 1d array and depending on the size updates only some of the fields in your struct (this is much like an overloaded constructor with different initializer signatures).

 

Paul

 

You can check out LAVA on scripting which can solve this difficult problem but this is a very advanced and difficult topic which is not suggested not supported by NI

Paul Falkenstein
Coleman Technologies Inc.
CLA, CPI, AIA-Vision
Labview 4.0- 2013, RT, Vision, FPGA
0 Kudos
Message 8 of 27
(17,400 Views)

I won't disagree with any of the previous posters, but would point out a conversion technique I just recently tried and found to work well for my own particular purposes.  I've given the method a pretty good workout and not found any obvious flaws yet, but can't 100% guarantee the behavior in all settings.

Anyhow, I've got a fairly good sized project that includes quite a few similar but distinct clusters of booleans.  Each has been turned into a typedef, complete with logical names for each cluster element.  For some of the data processing I do, I need to iterate over each boolean element in a cluster, do some evaluations, and generate an output boolean cluster.  I first structured the code to use the "Cluster to Array" primitive, then auto-index over the resulting array of booleans, perform the evaluations and auto-index an output array-of-booleans, then finally convert back using the "Array to Cluster" primitive.  I, too, was kinda bothered by having to hardcode cluster sizes in there...

I found I could instead use the "Typecast" primitive to convert the output array back to my cluster.  I simply fed the input cluster into the middle terminal to defin! the datatype.  Then the output cluster is automatically the right size and right datatype.

This still is NOT an adjustable cluster size, but it had the following benefits:

1. If the size of my typedef'ed cluster changes during development by adding or removing boolean elements, none of the code breaks!  I don't have to go searching through my code for all the "Array to Cluster" primitives, identifying the ones I need to inspect, and then manually changing the cluster size on them one at a time!

2. Some of my processing functions were quite similar to one another.  This method allowed me to largely reuse code.  I merely had to replace the input and output clusters with the appropriate new typedef.  Again, no hardcoded cluster sizes hidden in "Array to Cluster" primitives, and no broken code.

Dunno if your situation is similar, but it gave me something similar to auto-sizing at programming time.  (You should test the behavior when you feed arrays of the wrong size into the "Typecast" primitive.  It worked for my app's needs, but you should make sure it's right for yours.)

-Kevin P.

CAUTION! New LabVIEW adopters -- it's too late for me, but you *can* save yourself. The new subscription policy for LabVIEW puts NI's hand in your wallet for the rest of your working life. Are you sure you're *that* dedicated to LabVIEW? (Summary of my reasons in this post, part of a voluminous thread of mostly complaints starting here).
Message 9 of 27
(17,388 Views)
Kevin, that's an interesting method, but I would be careful with it. If NI chooses to modify the internal representation of any of the involved data types in future versions it could cause the code not to work. I would not expect this to work (I would expect the array to include size data in the header, but apparently that's ignored if it's there), but an inspection of the LV memory management white paper should probably reveal why it does.

___________________
Try to take over the world!
0 Kudos
Message 10 of 27
(17,384 Views)