06-25-2019 08:56 PM - edited 06-25-2019 09:07 PM
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?
Solved! Go to Solution.
06-26-2019 12:42 AM
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… 😄
06-26-2019 06:26 AM
As a bonus remark: you can use autoindexing to build an array in a (for) loop... No need for shift registers+build array.
06-26-2019 06:33 AM - edited 06-26-2019 06:34 AM
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
06-26-2019 06:44 AM - edited 06-26-2019 06:47 AM
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.
06-26-2019 07:12 PM - edited 06-26-2019 07:22 PM
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.
06-27-2019 02:01 AM
@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.
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?
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...
06-30-2019 09:28 PM
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?
07-01-2019 02:56 AM
@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.
07-01-2019 09:14 AM
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 ?
The only time I've ever seen "ISO" it always meant "in search of".