To download NI software, including the products shown below, visit ni.com/downloads.
Overview
To sort a 2 Dimensional Array based on the values specified in one of the columns.
Description:
This example shows how to sort a 2 Dimensional Array based on the values specified in one of the columns. The example sorts the rows in ascending order, but could be easily modified to descend instead. Essentially this behavior mimics the sort of sorting behavior you'd want in a spreadsheet.
The array can be resized but must remain 2 dimensional. The sorted contents are displayed in the array indicator on the right. This example works with any numeric array.
Instructions:
To implement this example:
To execute this example:
Requirements
Software
LabVIEW 2012 or compatible
Hardware
-
**This document has been updated to meet the current required format for the NI Code Exchange.**
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
http://wiki.openg.org/Sort_Array
James,
You are using the incorrect array size element for your loop count, you need to index by the zero'th element to iterate across rows (and hence sort by columns). Consequently this code only currently works for square arrays where the number of rows equals the number of columns. Have you considered using the OpenG Sort Array function (as mentioned by jordankeuhn) as an alternative? It allows sort by columns and rows, ascending or descending, and is polymorphic so numerous numeric types are accommodated.
Just trying to help