sorting specific columns of a matrix

1 Ansicht (letzte 30 Tage)
Ozgur Avsar
Ozgur Avsar am 24 Jan. 2016
Bearbeitet: Triveni am 13 Mär. 2016
trying not to sort entire matrix just the columns that conforms the rule. the example is a =[8 6 7; 9 6 7; 10 7 8; 9 9 8; 10 9 8; 9 9 10; 10 9 10; 11 9 10]; I want to sort the rows according to 2 and 3 respectively, but if the value on the second row is greater than the value on the third row this columns should also be sorted by the first column descending. The answer should be: b = [8 6 7; 9 6 7; 10 7 8; 10 9 8; 9 9 8; 9 9 10; 10 9 10; 11 9 10]; any advice?

Antworten (1)

Triveni
Triveni am 24 Jan. 2016
Bearbeitet: Triveni am 13 Mär. 2016
out = sort(a, 'descend');
for ascending order
sort(a, 'ascend');
  6 Kommentare
Ozgur Avsar
Ozgur Avsar am 24 Jan. 2016
a = [8 6 7; 9 6 7; 10 7 8; 9 9 8; 10 9 8; 9 9 10; 10 9 10; 11 9 10]; b = [8 6 7; 9 6 7; 10 7 8; 10 9 8; 9 9 8; 9 9 10; 10 9 10; 11 9 10]; b is the answer
Ozgur Avsar
Ozgur Avsar am 24 Jan. 2016
b=sortrows(a,[2 3]) but then?

Melden Sie sich an, um zu kommentieren.

Kategorien

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

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by