How to sort based on two columns
조회 수: 2 (최근 30일)
이전 댓글 표시
col1
42.8525 2 0.1475
15.4135 1 0.4135
17.9379 1 1.9379
43.7166 2 3.2834
41.1387 2 5.8613
39.0441 2 8.9559
49.2551 1 8.7449
29.5191 2 1.5191
40.7013 2 2.2987
35.2668 2 7.7332
35.8608 2 5.8608
22.4636 1 2.4636
51.207 1 8.793
32.5034 2 3.5034
42.3146 2 5.6854
16.6997 1 4.6997
I want the sort col 2 in ascending order i.e all 1's first and based on this in col 1 also i was it in ascending order,
then next all 2's in col 2 and accordingly col 1 to be sorted in ascending, corresponding value of col 3 is to be updated
I expect the output as follows
15.4135 1 0.4135
16.6997 1 4.6997
17.9379 1 1.9379
22.4636 1 2.4636
49.2551 1 8.7449
51.207 1 8.793
29.5191 2 1.5191
32.5034 2 3.5034
35.2668 2 7.7332
35.8608 2 5.8608
39.0441 2 8.9559
40.7013 2 2.2987
41.1387 2 5.8613
42.3146 2 5.6854
42.8525 2 0.1475
43.7166 2 3.2834
댓글 수: 0
답변 (1개)
Jon
2020년 10월 5일
You should be able to use sortrows for this. Please type doc sortrows on the command line for further documentation
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!