sort 3 column matrix by two key words

2 次查看(过去 30 天)
how to do this in matlab? sort the matrix raws first by the first column, then by the second column?
input = [
1 2 11
1 2 11
1 2 12
1 2 11
1 2 11
1 2 12
1 3 17
1 3 15
1 4 18
1 4 18
1 3 15
1 3 16
2 3 17
2 3 15
1 3 16
1 3 17
1 3 15
1 3 15
1 3 15
1 3 16
1 2 12
1 2 11
1 2 11
1 2 11
1 4 18
1 4 18
1 4 18
2 4 17
2 4 17
1 4 17
1 4 17
1 4 17
]
output = [1 2 11
1 2 11
1 2 12
1 2 11
1 2 11
1 2 12
1 2 12
1 2 11
1 2 11
1 2 11
1 3 17
1 3 15
1 3 15
1 3 16
1 3 16
1 3 17
1 3 15
1 3 15
1 3 15
1 3 16
1 4 18
1 4 18
1 4 18
1 4 18
1 4 18
1 4 17
1 4 17
1 4 17
2 3 17
2 3 15
2 4 17
2 4 17
]

采纳的回答

Walter Roberson
Walter Roberson 2017-12-5
output sortrows(input, [1 2]);
  1 个评论
HONG CHENG
HONG CHENG 2017-12-5
thanks a lot, this function is what I need.
I also have another question, maybe you are interested in it too
that problem in the link is based on this problem.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!