Sort in ascending order for first column then descending order for the second column.

조회 수: 8 (최근 30일)
Hi,
A=[1 1 1;
3 2 1;
1 3 1]
is there a way in matlab to sort rows of a matrix based on ascending order for the first column and then descending order for the second column, so the final matrix will look like this:
A=[1 3 1;
1 1 1;
3 2 1]

채택된 답변

Azzi Abdelmalek
Azzi Abdelmalek 2014년 3월 29일
A=[1 1 1; 3 2 1; 1 3 1]
B=sortrows(A,[1 -2])

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