sort 3 column matrix by two key words

2 views (last 30 days)
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
]

Accepted Answer

Walter Roberson
Walter Roberson on 5 Dec 2017
output sortrows(input, [1 2]);
  1 Comment
HONG CHENG
HONG CHENG on 5 Dec 2017
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.

Sign in to comment.

More Answers (0)

Categories

Find more on Shifting and Sorting Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!