LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Is it possible to remove elements of a cluster like removing/deleting rows/columns of a 2D array?

I have a single array of cluster.  I want to write the single array of cluster to file (maybe some of you remember this from last week).  But it's possible I don't want all the data in the cluster written to file.  But I also want to maintain the datatypes.  Is the following madness?  Deleting elements of a cluster?  Do clusters just not work that way?

0 Kudos
Message 1 of 14
(591 Views)

@LuminaryKnight wrote:

I have a single array of cluster.  I want to write the single array of cluster to file (maybe some of you remember this from last week).  But it's possible I don't want all the data in the cluster written to file.  But I also want to maintain the datatypes.  Is the following madness?  Deleting elements of a cluster?  Do clusters just not work that way?


Not unless the VI that serializes the Array of Cluster data to file supports it. The alternative is to create another Array of clusters with only the required elements by writing code that uses VI scripting to achieve this format A to format B conversion.

Santhosh
Soliton Technologies

New to the forum? Please read community guidelines and how to ask smart questions

Only two ways to appreciate someone who spent their free time to reply/answer your question - give them Kudos or mark their reply as the answer/solution.

Finding it hard to source NI hardware? Try NI Trading Post
0 Kudos
Message 2 of 14
(586 Views)

@santo_13 wrote:


Not unless the VI that serializes the Array of Cluster data to file supports it. The alternative is to create another Array of clusters with only the required elements by writing code that uses VI scripting to achieve this format A to format B conversion.


Yeah, I was thinking about doing it the alternative route.  Where a boolean array determines desired values and that there's a VI for each scenario... which is a lot of scenarios.

0 Kudos
Message 3 of 14
(580 Views)

@LuminaryKnight wrote:

I have a single array of cluster.  I want to write the single array of cluster to file (maybe some of you remember this from last week).  But it's possible I don't want all the data in the cluster written to file.  But I also want to maintain the datatypes.  Is the following madness?  Deleting elements of a cluster?  Do clusters just not work that way?


You asked the wrong question -- the problem is not that "clusters don't work that way", it is that arrays don't work that way.  In an Array, every element must be the same type, so if it is an Array of MyCluster, every element of the Array must be a "full member" of Type "My Cluster".  [Note -- if you use Clusters in your code, you will greatly help yourself if you create a TypeDef for your Cluster and refer to it by the name of the TypeDef.  Not only does this enforce the principle that the Cluster is a "thing", it allows you (especially if you create an Icon for the Cluster that you can recognize) makes it easy to spot the Cluster in your code by getting it to display its Icon].

 

Try this:

Combine Arrays of Different Sizes.png

 Look at the resulting array (but predict what you'll see before you try this ...)

 

Bob Schor (all of whose Clusters have a TypeDef)

 

 

0 Kudos
Message 4 of 14
(569 Views)

@Bob_Schor wrote:


You asked the wrong question -- the problem is not that "clusters don't work that way", it is that arrays don't work that way.  In an Array, every element must be the same type, so if it is an Array of MyCluster, every element of the Array must be a "full member" of Type "My Cluster".  [Note -- if you use Clusters in your code, you will greatly help yourself if you create a TypeDef for your Cluster and refer to it by the name of the TypeDef.  Not only does this enforce the principle that the Cluster is a "thing", it allows you (especially if you create an Icon for the Cluster that you can recognize) makes it easy to spot the Cluster in your code by getting it to display its Icon].

 

Bob Schor (all of whose Clusters have a TypeDef)


Oh, I love clusters.  And I hate clusters that aren't TypeDef... and try very hard not to judge developers who refuse to take the time to typedef them.  One of LabVIEW's greatest features, imo.

 

But I'd say you could argue there are 2 types of clusters.

  1. Grouping of numbers which is essentially a 2D array, but with the power of data types.
  2. Grouping of numbers, strings, refs, things, and/or more arrays. 

When I started learning about Object Oriented programming, I struggled with understanding the difference/purpose of objects versus clusters.  I thought, these are just clusters, which they still technically are.  My point: you can have cluster that represents 2D array, or a cluster that is essentially an object.

 

Maybe NI/LabVIEW should enforce this difference.  Remove "cluster" and call the 2D array version a grouping where we have the power to remove elements and the other call an object.  Just... you'd never end up using it to inherit from.  But you'd have the option.  This might could be to the benefit of many developers.  Where you essentially enforce Object Oriented mindset.

0 Kudos
Message 5 of 14
(559 Views)

You could (possibly) make this work with OO.  Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately.  But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that?  It is spelled "N", "I", "G", "H", "T", "mare".

 

Bob Schor

Message 6 of 14
(548 Views)

@Bob_Schor wrote:

You could (possibly) make this work with OO.  Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately.  But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that?  It is spelled "N", "I", "G", "H", "T", "mare".

 

Bob Schor


Yeah, I'm sitting here and I'm thinking... "I might just tell user/client... nope, you just get everything."  The end.

0 Kudos
Message 7 of 14
(545 Views)

@Bob_Schor wrote:

You could (possibly) make this work with OO.  Create an Object "Array of 3 Dbl" and Object "Array of 5 Dbl", then you could make an array of these Objects, and at run time, handle the "3 Dbl" and "5 Dbl" separately.  But don't forget to make "Array of 6 Dbl", and if the "3 Dbl" came from the middle 3 elements of the "5 Dbl" on one call, and the first three elements on another call, how are you going to handle that?  It is spelled "N", "I", "G", "H", "T", "mare".

 

Bob Schor


I am playing with the idea of typecasting the Array of Cluster to Array of U8, where there I can delete columns/rows of undesired data before sending to binary file.  This might have merit with results I'm seeing so far.

0 Kudos
Message 8 of 14
(518 Views)

@LuminaryKnight wrote:
I am playing with the idea of typecasting the Array of Cluster to Array of U8, where there I can delete columns/rows of undesired data before sending to binary file.  This might have merit with results I'm seeing so far.

Since LabVIEW is a fully featured programming language, you can do anything you want. All you need to do is implement the saving to file where you remove unwanted data as well as restoring from file, where you convert back to array of clusters in a way to only touch the saved elements. Still, seems like unneeded complications....

0 Kudos
Message 9 of 14
(482 Views)

@LuminaryKnight wrote:

I have a single array of cluster.  I want to write the single array of cluster to file (maybe some of you remember this from last week).  But it's possible I don't want all the data in the cluster written to file.  But I also want to maintain the datatypes.  Is the following madness?  Deleting elements of a cluster?  Do clusters just not work that way?


The simple solution is to remove the element from the cluster (which i assume/hope is type def'd), but that might mess up other parts of your program. So the 2nd option is to simply filter the data before saving it to file, and if you want it dynamic, you'll have some ini-file where you write down which elements should go into the result file.

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

Qestit Systems
Certified-LabVIEW-Developer
0 Kudos
Message 10 of 14
(391 Views)