Sort 2D Array
- Updated2025-07-30
- 3 minute(s) read
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.

Inputs/Outputs
2D array
—
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 (column)
—
dimension to index specifies the dimension of the 2D array to sort by.
index
—
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
—
sorted 2D array returns a sorted version of the 2D array.
index out of range?
—
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. |
The example below demonstrates how this VI sorts the following 2D array if dimension to index is column.
| Alice | 28 | Female | developer |
| Robert | 31 | Male | Manager |
| David | 29 | Male | Technician |
| Kate | 29 | Female | Engineer |
If index is 1, this VI returns the following array.
| Alice | 28 | Female | developer |
| David | 29 | Male | Technician |
| Kate | 29 | Female | Engineer |
| Robert | 31 | Male | Manager |
If index is 3, this VI returns the following array.
| Kate | 29 | Female | Engineer |
| Robert | 31 | Male | Manager |
| David | 29 | Male | Technician |
| Alice | 28 | Female | developer |
If index is {2, 0}, this VI returns the following array.
| Alice | 28 | Female | developer |
| Kate | 29 | Female | Engineer |
| David | 29 | Male | Technician |
| Robert | 31 | Male | Manager |
Examples
Refer to the following example files included with LabVIEW.
- labview\examples\Malleable VIs\Basics\Malleable VIs Basics.lvproj
2D array
—
dimension to index (column)
—
index
—
sorted 2D array
—
index out of range?
—