Based on an algorithm posted by "a. g." (https://decibel.ni.com/content/docs/DOC-13719#comment-51386), this code was inspired because that algorthigm had errors on Descending order. I needed a robust, polymorphic solution that I could trust to sort safely, in any column order, in any direction. This fits the bill.
This VI takes any standard datatype 2D array, sorts on one or more columns in the index order you select, and optionally switches all column sorts from Ascending to Descending.
The attached ZIP has the entire collection of polymorphic VI's - or you can view the images below for how it is done. It is in LV2012 because that's what I was building with at the time 😉
Improvements over a. g.'s original posting:
Note to NI: I haven't used the newest versions of LV yet, but I would love to see this and other 2D VI's (ex. 2D Invert by Columns or Rows I also have) added to the core.
Not commenting the sorting algorithm itself, one simple way to improve the efficiencyof this code is to rewrite the way it reverses the array if descending is set to true. Right now the code rebuids the string array one row at a time, which is extremely costly.
One of the simplest alternative ways to do this is to transpose the array, feed it to an autoindexing for/loop with a reverse 1D array node in it, then wire the output out of the for loop and do another transpose on it. For a 5000x5 string array for example this makes the reversation more than 350 times faster on my test machine (with debugging turned off).
Thanks Mads! Sounds like a great performance enhancement, and it makes sense why.
Tim