Example Code

2D Array Sorter

Products and Environment

This section reflects the products and operating system used to create the example.

To download NI software, including the products shown below, visit ni.com/downloads.

    Software

  • LabVIEW

Code and Documents

Attachment

Download All

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:

  1. Run the VI
    Selecting a column (n) and running the VI will sort all of the rows in ascending order based on the values in the nth column. Supports any size of 2 dimensional array.


To execute this example:

  1. Install the required software.
  2. Open the VI and refer the Implement Steps


Requirements
Software
LabVIEW 2012 or compatible

Hardware
-

fp.PNGbd.png

**This document has been updated to meet the current required format for the NI Code Exchange.**

Product Support Engineer
National Instruments

Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.

Comments
jordankuehn
Member
Member
on

http://wiki.openg.org/Sort_Array

The Colex Group
Lead Software Engineer
Certified LabVIEW Developer
Thoric
Trusted Enthusiast Trusted Enthusiast
Trusted Enthusiast
on

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

Thoric (CLA, CLED, CTD and LabVIEW Champion)