01-20-2016 09:03 AM
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.
Solved! Go to Solution.
01-20-2016 03:41 PM
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:
Bob Schor
01-20-2016 03:54 PM
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.
01-21-2016 03:18 PM
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?
01-21-2016 05:16 PM
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:
v2014:
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.
01-22-2016 02:47 PM
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!
01-29-2016 09:24 AM
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!
11-08-2021 09:04 AM - edited 11-08-2021 09:06 AM
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.