5

I was playing around with the most basic functions of LabVIEW such as converting single elemtents to arrays and cluster, back and forth. (Don't question the use of the shown algorithm, there is none.)

When converting a cluster (of similar types of course) to an array, using that for a simple mathematical operation, and converting it back to a cluster the following unbundle to splits the cluster into its individual elements behaves strangely. Connecting the unbundle to this existing cluster it automatically increases its size to 9 instead of the expected 3. The probes and the numeric indicators show that the elements above the three first items are zero.

Why is this? I would expect that array to cluster knows the size of the converted array and fits the cluster accordingly.

enter image description here

enter image description here

Ghanima
  • 409
  • 10
  • 24

1 Answers1

6

While one could expect that Array To Cluster applys the size of the array to the cluster automatically, it instead uses a fixed default value regardless of the size of the underlying array:

The default is nine. The maximum cluster size for this function is 256.

Source: http://zone.ni.com/reference/en-XX/help/371361J-01/glang/array_to_cluster/

This value can be changed by right-clicking the function and selecting Cluster Size from the shortcut menu. Unfortunately that also means to manually fix this everytime the array is changed.

Explanation: The reason for this behaviour is that while the size of an array can vary dynamically at runtime, the data structure of a cluster is fixed at compile time (LabVIEW is a strongly-typed language). The compiler needs to be told the size of the cluster. If you really need to create arbitrary clusters at runtime you can probably do something with variants, but I'd take another look at what you're trying to achieve to check whether it's really necessary.

Ghanima
  • 409
  • 10
  • 24
  • 2
    The reason for this behaviour is that while the size of an array can vary dynamically at runtime, the structure of a cluster is fixed at compile time - that's just how LabVIEW was designed. If you really need to create arbitrary clusters at runtime you can probably do something with variants, but I'd take another look at what you're trying to achieve to check whether it's really necessary. – nekomatic Mar 24 '17 at 08:48
  • 2
    @nekomatic I merged your comment into the answer. Comments on SO can be deleted, so info that directly improve the answer are encouraged to merge into the answer. It also makes it more coherent for people reading the answer to not have to sort through comments to get the whole answer. :-) – srm Mar 24 '17 at 14:00
  • @nekomatic thanks for the explanation. To clarify there is no real use case right now. I am just following a basic instructions guide and play with the features as they are discussed. – Ghanima Mar 24 '17 at 18:40