sortrows
Sort rows of matrix or table
Syntax
Description
sortsB
= sortrows(A
,column
)A
based on the columns specified in the vectorcolumn
. For example,sortrows(A,4)
sorts the rows ofA
in ascending order based on the elements in the fourth column.sortrows(A,[4 6])
first sorts the rows ofA
based on the elements in the fourth column, then based on the elements in the sixth column to break ties.
sorts the rows ofB
= sortrows(___,direction
)A
in the order specified bydirection
for any of the previous syntaxes.direction
can be'ascend'
(default) for ascending order or'descend'
for descending order.direction
can also be a cell array whose elements are'ascend'
and'descend'
, where each element corresponds to a column thatsortrows
operates on. For example,sortrows(A,[4 6],{'ascend' 'descend'})
sorts the rows ofA
in ascending order based on the fourth column, then in descending order based on the sixth column to break ties.
specifies additional parameters for sorting rows. For example,B
= sortrows(___,Name,Value
)sortrows(A,'ComparisonMethod','abs')
sorts the elements ofA
by magnitude.
sorts the rows of a table or timetable.结核病lB
= sortrows(结核病lA
)
If
结核病lA
is a table, thensortrows
sorts结核病lA
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
结核病lA
is a timetable, thensortrows
sorts the rows of结核病lA
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.Row times of a timetable are
datetime
orduration
values that label the rows along the first dimension of the timetable.
sorts a table based on its row names. Row names of a table label the rows along the first dimension of the table. If结核病lB
= sortrows(结核病lA
,'RowNames')结核病lA
does not have row names, that is, if结核病lA.Properties.RowNames
is empty, thensortrows
returns结核病lA
.
This syntax is not supported when结核病lA
is a timetable.
sorts结核病lB
= sortrows(结核病lA
,rowDimName
)结核病lA
by row labelsrowDimName
along the first dimension.
If
结核病lA
is a table, then row labels are row names.If
结核病lA
is a timetable, then row labels are row times.
sorts a table by the elements in the variables specified by结核病lB
= sortrows(结核病lA
,vars
)vars
. For example,sortrows(tblA,{'Var1','Var2'})
first sorts the rows of结核病lA
based on the elements inVar1
, then by the elements inVar2
.
If
结核病lA
is a table and it has row names, thenvars
can include the row names.If
结核病lA
is a timetable, thenvars
can include the row times.
sorts结核病lB
= sortrows(___,direction
)结核病lA
in the order specified bydirection
for any of the previous table syntaxes.direction
can be'ascend'
or'descend'
, which is applied to all specified variables, row names, or row times thatsortrows
operates on.direction
can also be a cell array whose elements are'ascend'
and'descend'
, where each element corresponds to the specified variables, row names, or row times being sorted on.
specifies additional parameters for sorting rows of a table or timetable. For example,结核病lB
= sortrows(___,Name,Value
)sortrows(tblA,'Var1','MissingPlacement','first')
sorts based on the elements inVar1
, ordering missing elements such asNaN
at the beginning of the table.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced before R2006a