I spent about 3 hours today circumventing the idea of sorting 2-D arrays in Labview. I had a 2-D array of 3 values. My plan was to reorder the array by one of the values while keeping the other values in the same index.
For example, this array:
[0] 6 14 28
[1] 7 81 4
[2] 1 15 38
I would want to sort it by column 3 making it this:
[0] 7 81 4
[1] 6 14 28
[2] 1 15 38
Does anyone know of a simple way to do this, or should I stick with my excessive, hard-to-follow code that I don’t think I’ll ever understand now that I’ve finished writing it?
With only three elements, it may be enough to avoid “sorting” sorting altogether, and just use a few IF statements. Not practical for larger sorts, but it might be best in this case.
have you considered storing the 2d array as a 1-d array of clusters? that way you could store the item you want to sort by in the first slot and just do a 1-d built in sort.
Unfortunately, there is no easy way to tell LV exactly how to sort more complicated data containers. LV deals with almost any type, but only 1D containers, sorted by first, then second, etc, and only in ascending order.
The attached snippet shows how to build an index array, then rebuild the 2D array based upon the indices.