LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I append data to arrays inside a cluster in a scalable way

Solved!
Go to solution

I have used a cluster to collect many 1D arrays to simplify wiring.

However, I want to append new data to all the arrays in the cluster, as in the attached snippet for the simple example of 2 arrays in a cluster.

The snippet works, but will need extra code added to correctly append arrays if I change the cluster typedef. Is there a way to operate with clusters to do the same function in a scalable way?

support snippet.png

0 Kudos
Message 1 of 11
(4,263 Views)

Hi Brad,

 

Is there a way to operate with clusters to do the same function in a scalable way?

No.

Clusters define a datatype and so dictate how to handle them in the block diagram.

When you change that datatype you (often) need to adapt your VI too.

 

Suggestions:

- Give labels to the cluster elements to be able to use (Un)BundleByName.

- Think about an array of clusters (of whatever) to be able to autoindex that array…

- It really helps to design an algorithm (and its datastructures) before starting to code… 😄

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 11
(4,218 Views)

As a bonus remark: you can use autoindexing to build an array in a (for) loop... No need for shift registers+build array.

0 Kudos
Message 3 of 11
(4,200 Views)

How to make it scalable? Instead of having a Cluster with arrays, there's 2 ways to make it easily scalable:

- If you always add as much data (as per your example), you can simply change the data to a 3D array.

- If they're different sized arrays, you can change to an Array of Clusters, each containing an array. If that is encapsuled in a Cluster to group it all or not is more of a stylistic thing.

 

The thing to take with you is that many/most functions seems optimized around arrays in LV, so it's always a solid idea to think/implement ideas as arrays. 🙂

/Y

G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 4 of 11
(4,198 Views)

Depending on how present this 'cluster' is in your application, you can consider some sort of container to manage the data.

 

For instance, a class or a functional global. You can use a (type def'd!) enum to index the data when setting or getting the data. A FG would be global, a class by wire. Both have there ups and downs, choose wisely.

 

The internals are not really relevant. It can sometimes be a 2D array, or an array of 1 element clustered arrays.

 

A cluster with arrays is highly impractical, as it's hard to programmatically access elements. Variants do allow this, but it's not fast.

Message 5 of 11
(4,190 Views)

I found a solution using the cluster toolkit. However I had trouble installing this, JKI package manager didn't work from its own search. I had to use a link from a NI.com page.

 

I do like the idea of the functional global to do what I want, as it keeps the names. This is why I didn't just use 2D arrays - as I want to keep the names for plotting the data (which aren't shown in the simple example posted).

 

I haven't installed LV2019 yet, but the new type 'map' might have been useful too.

solution snippet.png

0 Kudos
Message 6 of 11
(4,173 Views)
Solution
Accepted by BradC

@BradC wrote:

I found a solution using the cluster toolkit. However I had trouble installing this, JKI package manager didn't work from its own search. I had to use a link from a NI.com page.

 

I do like the idea of the functional global to do what I want, as it keeps the names. This is why I didn't just use 2D arrays - as I want to keep the names for plotting the data (which aren't shown in the simple example posted).

 

I haven't installed LV2019 yet, but the new type 'map' might have been useful too.

solution snippet.png


That's going to be dramatically slow. Variant-Cluster-Variant conversion won't win any speed contests...

 

Not sure why a FG wouldn't be able to use a 2D array, the two solutions are not mutually exclusive.

 

Why not keep it really simple?

 

Read Write Array.PNG

 

Note that iso an integer, you can use an (TD'd) enum if the elements are fixed and known.

Note that iso an array w\ clusters, you can use a set (or variant attributes) and a string name.

 

Note that if you put this in a class, you can switch implementations with minimal effect on your application...

0 Kudos
Message 7 of 11
(4,153 Views)

Perhaps I could have been clearer. I didn't mean that FG can't use 2D arrays.

I didn't use 2D arrays for my problem, as I wanted to keep the array labels.

 

What do you mean by iso?

0 Kudos
Message 8 of 11
(4,123 Views)

@BradC wrote:

Perhaps I could have been clearer. I didn't mean that FG can't use 2D arrays.

I didn't use 2D arrays for my problem, as I wanted to keep the array labels.


Keep the labels?

 

If you put them in a 2D array (or an array in a cluster in an array, or a set\variant attribure), the index of that array would be the 'label'. It would be solid.

 


@BradC wrote:

What do you mean by iso?


InStead Of.

0 Kudos
Message 9 of 11
(4,110 Views)

wiebe@CARYA wrote:

 


@BradC wrote:

What do you mean by iso?


InStead Of.


Weibe!  Do I need to point you to A plea for full words ?   Smiley Wink

 

The only time I've ever seen "ISO" it always meant "in search of". 

0 Kudos
Message 10 of 11
(4,098 Views)