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.


icon

Inputs/Outputs

  • c2dfxdt.png 2D array

    2D array specifies the 2D array that you want to sort.

    This input accepts an array of any data type except refnums.

  • cenum.png dimension to index (column)

    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.
  • ci32.png 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.

  • i2dfxdt.png sorted 2D array

    sorted 2D array returns a sorted version of the 2D array.

  • ibool.png 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.

    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.

    Examples

    Refer to the following example files included with LabVIEW.

    • labview\examples\Malleable VIs\Basics\Malleable VIs Basics.lvproj