Creating a Custom Sorting Function in LabVIEW.

Updated Mar 24, 2022

Environment

Software

  • LabVIEW

If you want to use Sort 1D Array.vi to compare an array of custom data, you will need to create a custom comparison class. In order to do that follow the steps below.

To be able to create a custom comparison class, we need to copy the original. For example, to make a custom comparison class for Sort 1D Array.vi, we would need to copy the Less Functor.lvclass, as the Sort 1D array.vi  is using less than function by default, which belongs to aforementioned class. In order to copy the class:

1. Close any VI or project which might use the function belonging to that class.
2. Go to LabVIEW>>Help>>Find Examples...
3. In NI Example Finder Window go to Search and type malleable and open Malleable VIs - Nested Malleable VIs.
a1.png
4. In the Dependencies of that project you can see different comparator classes. Right click on the class with the required functionality and choose Save>>Save As and create a copy of the class.
a2.png
5. Modify the main comparison VI of the class to your liking. Make sure to wire the terminals of the new controls you are comparing.

Now you have created a custom comparison class, and when wiring its main comparison VI as an input to the Sort 1D Array.vi or any other VI that uses a comparison class, you can compare array of any custom data type.

Here is an example of a custom comparison class using clusters. Below is the modified Less Than.vi of that class.
A3.png
And here you can see that when we wire the class to the Sort 1D Array.vi, we have no broken wires.
a4.png