필터 지우기
필터 지우기

sorting data in matrix

조회 수: 2 (최근 30일)
Kieran
Kieran 2013년 10월 18일
편집: Andrei Bobrov 2013년 10월 18일
say i have a matrix
a = [2 3; 1 3; 3 2; 2 2; 1 2; 3 1; 2 1; 1 1]
i would like to rearrange a such that the first column is sorted in ascending order corresponding to the number in the second column ie. this matrix should become
asorted = [1 3; 2 3; 1 2; 2 2; 3 2; 1 1; 2 1; 3 1]
how can this be done automatically

채택된 답변

Andrei Bobrov
Andrei Bobrov 2013년 10월 18일
편집: Andrei Bobrov 2013년 10월 18일
asorted = sortrows(a,[-2 1])

추가 답변 (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!

Translated by