LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

compare mixed-data clusters that include some floats

Solved!
Go to solution

Has anyone come up with what they consider to be a slick way to compare mixed-data (including floats) clusters for functional (close enough) equality? All I've manged to come up with are specific-to-the-cluster VIs that use a while loop with a internal index-driven case statement to step through the clusters element by element to make the comparisons, using an appropriate method for comparing the floats that will accept a tolerance.  I thought perhaps that someone may have already built a more generic solution built on converting the clusters to variant data and then steering each data element to a correct comparison for its data type.

0 Kudos
Message 1 of 8
(4,584 Views)

Well, you can use the "Close-enough" methods in the note you cite, just expand to fit your cluster.  I'm assuming the Cluster is all numeric (you can certainly compare a really-mixed Cluster with strings, booleans, and numerics, but then my method would fail).

 

I'm using the "less than an absolute threshold" method for illustration.  The one "catch" is you need to create the "base cluster" more-or-less by hand, though you can set all of the threshold values the same, as shown here:

Compare Clusters.png

Bob Schor

0 Kudos
Message 2 of 8
(4,546 Views)

Thanks Bob but my clusters generally fall into the "really mixed" category.  The current one I'm working with has a string plus an array-of-cluster at the upper level with the array's cluster elements consisting of DBLs, various-sized INTs, a couple of ENUMs and a string.  Using some pieces from the AutoTestWare toolkit I have spent the morning cobbling together something that seems to be working for the few clusters I've thrown at it. At the moment I'm trying to figure out what to do with some of the more left-field variant data types that can be produced.

0 Kudos
Message 3 of 8
(4,538 Views)

Unfortunately, there is no catch all method for doing a functional equals method.

If you see the method that works the best for you, you could create subVIs that meet your needs, and that would decrease your work in the long run for each mixed cluster that you have.

 

If you find that the cluster doesn't require any functional equals, then you can compare the entire cluster to get a cluster of booleans for each value. But as far as I can see, you are on the right track of creating a loop to iterate through each one. 

 

What 'left-field' data types are you running into?

0 Kudos
Message 4 of 8
(4,490 Views)

What 'left-field' data types are you running into?

These are what stand out so far. I don't think I'm missing much by ignoring them. They vary by LabVIEW version as the later versions pick up more esoteric datatypes. I think I have the other cases handled well enough but no guarantees as I have not tested them all.

 

v8.0:

Clipboard01.jpg

 

v2014:

Clipboard02.jpg

 

I've attached the 8.0 & 2014 versions of the VI to this post in case it might prove useful for anyone else. The paint's not dry on it yet but it does work with the few clusters, arrays and simple values which I've thrown at it.  The attached code, rather than using the AutoTestWare toolkit mentioned before, instead is built on (what I think to be) the more generally used OpenG toolkit and you will need to have that installed to be able to use the VI.

Message 5 of 8
(4,475 Views)

I believe that you are on the right track with this. Because of the complicated and specific nature, there isn't much out there to compare clusters to be functionally close in a 'slick' manner.

 

This may be something really good to upload as a community example when you are finished, though!

0 Kudos
Message 6 of 8
(4,441 Views)
Solution
Accepted by topic author WNM

The attached Zip file has v7.1.1, v8.0 and v2014 versions of my VI to make this comparison. I needed to rework the case that handled RefNum objects to allow for the fact that they can either be numeric or ASCII (e.g. VISA). I also added an error output so that it's easier to tell when the process runs off the rails. At this point I'm going to say that I'm done with this because what I have created does what I need it to do and the NI forum elves are pestering me to mark something in this thread as an answer. Enjoy!

0 Kudos
Message 7 of 8
(4,371 Views)

WNM,

 

This is a very useful vi; I think it would be a good submission to idea exchange/example programs. I've needed a vi like this on multiple occasions, so I really appreciate that someone has made one.

 

I've updated your vi to use the cluster/variant library instead of OpenG for anyone who does not have it. Limitation: my version of the vi had to change how a variant of type multi-dimensional array could be reshaped to a variant of type 1-D array; it only does so for up to a 20-D array do to the lack of OpenG in my instance of Labview.

Using Labview 2022, Windows 10
Download All
0 Kudos
Message 8 of 8
(2,318 Views)