s o r t r o w s sortrows sortrows函数依据某列的属性对其元素所在的行进行排序从而进行矩阵的排序
-
s
o
r
t
r
o
w
s
sortrows
sortrows函数常用方法:
1. 1. 1. s o r t r o w s ( a , [ c 1 , c 2 ] ) sortrows(a,[c_1,c_2]) sortrows(a,[c1,c2]),( c i c_i ci可依据矩阵延续)先基于矩阵第 c 1 c_1 c1列升序排序,若第 c 1 c_1 c1列上有两元素相同,将它们所在的行基于 c 2 c_2 c2列按升序排列,若 c 2 c_2 c2列上仍有两元素相同,则按照元素出现的先后顺序进行排序;当对所有列都排序时,可简写成 s o r t r o w s ( a ) sortrows(a) sortrows(a)
2.
2.
2. 对于不同列的不同升序或降序要求,可以用
s
o
r
t
r
o
w
s
(
a
,
[
c
1
,
c
2
]
,
sortrows(a,[c_1,c_2],
sortrows(a,[c1,c2],
{
′
d
e
s
c
e
n
d
′
,
′
a
s
c
e
n
d
′
}
\lbrace'descend','ascend'\rbrace
{′descend′,′ascend′}
)
)
)表达,表示将第
c
1
c_1
c1列按降序对矩阵排序,如果有元素相同,将它们所在的行按第
c
2
c_2
c2列升序排序,若
c
2
c_2
c2列上仍有两元素相同,则按照元素出现的先后顺序进行排序
3.
3.
3.与
s
o
r
t
sort
sort函数一样,
s
o
r
t
r
o
w
s
sortrows
sortrows函数也有返回索引功能,
s
o
r
t
r
o
w
s
sortrows
sortrows函数返回的索引是某一行在原矩阵中处在第几行的位置,对以上各种操作都可以
[
s
o
r
t
r
o
w
s
a
,
i
d
]
=
s
o
r
t
r
o
w
s
(
)
[sortrows_a,id]=sortrows( )
[sortrowsa,id]=sortrows()求索引,例如: