Sort 2D Array VI

Owning Palette: Array VIs and Functions

Requires: Base Development System

Rearranges the rows or columns of a 2D array by sorting the elements in the specified column or row in ascending order.

This VI rearranges the elements in the specified column or row in ascending order by comparing the elements using comparison rules for different data types.

Details  Example

 Add to the block diagram  Find on the palette
2D array specifies the 2D array that you want to sort.

This input accepts an array of any data type except refnums.
dimension to index specifies the dimension of the 2D array to sort by.

0column (default)—Rearranges the rows by sorting the elements in the indexed column in ascending order.
1row—Rearranges the columns by sorting the elements in the indexed row in ascending order.
index specifies the index of the column or row with elements that you want to rearrange.

This input accepts a signed 32-bit integer or an array of signed 32-bit integers.
sorted 2D array returns a sorted version of the 2D array.
index out of range? returns TRUE if the indexed column or row, or any of the indexed columns or rows does not exist in the 2D array. Otherwise, this output returns FALSE.

Sort 2D Array Details

The example below demonstrates how this VI sorts the following 2D array if dimension to index is column.

Alice28Femaledeveloper
Robert31MaleManager
David29MaleTechnician
Kate29FemaleEngineer

If index is 1, this VI returns the following array.

Alice28Femaledeveloper
David29MaleTechnician
Kate29FemaleEngineer
Robert31MaleManager
Note  If multiple rows have the same element for the indexed column, this VI keeps the original order of rows.

If index is 3, this VI returns the following array.

Kate29FemaleEngineer
Robert31MaleManager
David29MaleTechnician
Alice28Femaledeveloper
Note  For string elements, this VI rearranges the elements based on case-sensitivity. In this example, the indexed column contains the following elements: developer, Manager, Technician, Engineer. This VI rearranges this column to Engineer, Manager, Technician, developer.

If index is {2, 0}, this VI returns the following array.

Alice28Femaledeveloper
Kate29FemaleEngineer
David29MaleTechnician
Robert31MaleManager
Note  If index is an array, this VI rearranges the elements in the indexed columns in order. In this example, this VI rearranges first the elements in column 2 to be ascending, and then the elements in column 0.

Example

Refer to the Malleable VIs Basics.lvproj in the labview\examples\Malleable VIs\Basics directory for an example of using the Sort 2D Array VI.

 Open example  Find related examples