sortrows
Sort rows of matrix or table
Syntax
Description
Array Data
specifies additional parameters for sorting rows. For example,
B
= sortrows(A
,___,Name,Value
)sortrows(A,'ComparisonMethod','abs')
sorts the elements
in A
by magnitude.
Table Data
sorts the rows of a table or timetable.tblB
= sortrows(tblA
)
If
tblA
is a table, thensortrows
sortstblA
in ascending order based on the values in the first variable. If elements in the first variable are repeated, thensortrows
sorts by the elements in the second variable, and so on.If
tblA
is a timetable, thensortrows
sorts the rows oftblA
in ascending order based on its row times. However, the rows are sorted only with respect to the row times. If row times are repeated, thensortrows
does not sort by the elements in the timetable variables.
sorts a table based on its row names. Row names of a table label the rows along
the first dimension of the table. If tblB
= sortrows(tblA
,'RowNames')tblA
does not have row
names, that is, if tblA.Properties.RowNames
is empty, then
sortrows
returns tblA
.
This syntax is not supported when tblA
is a
timetable.
sorts based on row labels along the first dimension.tblB
= sortrows(tblA
,rowDimName
)
If
tblA
is a table, then row labels are row names.If
tblA
is a timetable, then row labels are row times.
sorts based on the specified table variables. For example,
tblB
= sortrows(tblA
,vars
)sortrows(tblA,{'Var1','Var2'})
first sorts the rows of
tblA
based on the elements in Var1
,
then by the elements in Var2
.
If
tblA
is a table and it has row names, thenvars
can include the row names.If
tblA
is a timetable, thenvars
can include the row times.
specifies additional parameters for sorting rows of a table or timetable. For
example, tblB
= sortrows(tblA
,___,Name,Value
)sortrows(tblA,'Var1','MissingPlacement','first')
sorts based on the elements in Var1
, ordering missing
elements such as NaN
at the beginning of the table.
Examples
Input Arguments
Name-Value Arguments
Output Arguments
Extended Capabilities
Version History
Introduced before R2006a
See Also
issortedrows
| sort
| issorted
| topkrows