I have a matrix
group =
0 0 0 1
0 1 0 0
0 0 1 0
0 1 0 0
0 0 0 1
0 0 1 0
0 0 1 0
0 1 0 0
0 0 0 1
0 1 0 0
1 0 0 0
0 1 0 0
if I want to sort in ascending order I can use
sortrows(group)
ans =
0 0 0 1
0 0 0 1
0 0 0 1
0 0 1 0
0 0 1 0
0 0 1 0
0 1 0 0
0 1 0 0
0 1 0 0
0 1 0 0
0 1 0 0
1 0 0 0
but I want to sort in descending order. What to do?

 채택된 답변

the cyclist
the cyclist 2012년 4월 21일

0 개 추천

You can use a second input argument. By omitting it, you have effectively used
sortrows(group,[1 2 3 4])
for the ascending case. I believe what you want for the descending case is
sortrows(group,[-1 -2 -3 -4])
but you should verify that the result.

추가 답변 (1개)

bym
bym 2012년 4월 21일

0 개 추천

sort(group,1,'descend')

댓글 수: 3

the cyclist
the cyclist 2012년 4월 21일
I don't think this method retains the integrity of the rows, but rather sorts the columns independently.
Asawari
Asawari 2013년 10월 18일
Can I use this descend command to arrange any array or matrix in descending order?I am using mesh command to create a curve.Mesh command creates origin of the curve between X-Y plane by default.I want to change the origin from X-Y plane to Y-Z plane and X axis I want to arrange in descending order,I am stuck here,can anyone help?
the cyclist
the cyclist 2013년 10월 18일
I suggest you make a new question, with more detail and maybe a small example. Questions buried in comments don't get seen as much.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

제품

태그

질문:

2012년 4월 21일

댓글:

2013년 10월 18일

Community Treasure Hunt

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

Start Hunting!

Translated by