Filter löschen
Filter löschen

sorting a matrix in descending order

2 Ansichten (letzte 30 Tage)
Rabeya
Rabeya am 21 Apr. 2012
Kommentiert: the cyclist am 18 Okt. 2013
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?

Akzeptierte Antwort

the cyclist
the cyclist am 21 Apr. 2012
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.

Weitere Antworten (1)

bym
bym am 21 Apr. 2012
sort(group,1,'descend')
  3 Kommentare
Asawari
Asawari am 18 Okt. 2013
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 am 18 Okt. 2013
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by