Documentation

This is machine translation

Translated by Microsoft
Mouse over text to see original. Click the button below to return to the English verison of the page.

sortcols (DataMatrix)

Sort columns of DataMatrix object in ascending or descending order

Syntax

DMObjNew = sortcols(DMObj1)
DMObjNew = sortcols(DMObj1, Row)
DMObjNew = sortcols(DMObj1, 'ColName')
DMObjNew = sortcols(DMObj1, ..., Mode)
[DMObjNew, Indices] = sortcols(DMObj1, ...)

Input Arguments

DMObj1

DataMatrix object, such as created by DataMatrix (object constructor).

Row

One or more rows in DMObj1 by which to sort the columns. Choices are:

  • Positive integer

  • Vector of positive integers

  • Character vector specifying a row name

  • Cell array of character vectors specifying multiple row names

  • Logical vector

'ColName'

Character vector that specifies to sort the columns by the column names.

Mode

Character vector specifying the order by which to sort the columns. Choices are 'ascend' (default) or 'descend'.

Output Arguments

DMObjNew

DataMatrix object created from sorting the columns of another DataMatrix object.

Indices

Index vector that links DMObj1 to DMObjNew. In other words, DMObjNew = DMObj1(:,idx).

Description

DMObjNew = sortcols(DMObj1) sorts the columns in DMObj1 in ascending order based on the elements in the first row. For any columns that have equal elements in a row, sorting is based on the row immediately below.

DMObjNew = sortcols(DMObj1, Row) sorts the columns in DMObj1 in ascending order based on the elements in the specified row. Any columns that have equal elements in the specified row are sorted based on the elements in the next specified row.

DMObjNew = sortcols(DMObj1, 'ColName') sorts the columns in DMObj1 in ascending order according to the column names.

DMObjNew = sortcols(DMObj1, ..., Mode) specifies the order of the sort. Mode can be 'ascend' (default) or 'descend'.

[DMObjNew, Indices] = sortcols(DMObj1, ...) returns Indices, an index vector that links DMObj1 to DMObjNew. In other words, DMObjNew = DMObj1(:,idx).

Introduced in R2008b

Was this topic helpful?