Sort data based on different column
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Pallav Patel
am 7 Apr. 2020
Bearbeitet: Peter O
am 7 Apr. 2020
a = [5 8 1 2 7 6 3 4
70 60 50 40 30 20 10 0]
I would like to sort the data based on the first row. [1 2 3 4 5 6 7 8 9 10;70 60 50 40 30 20 10 0];
I have tried using loops and the sort command but have had no luck. Could somebody help me figure out.
0 Kommentare
Akzeptierte Antwort
Peter O
am 7 Apr. 2020
Bearbeitet: Peter O
am 7 Apr. 2020
Try using the sortrows command in conjunction with a transpose. Apply it once to exploit column sorts (e.g. Column 1 is Row 1 above), and then again after the sort to put it back into the dimensions you want.
a = [5 8 1 2 7 6 3 4
70 60 50 40 30 20 10 0]
sorted_a = sortrows(a.',1).'
0 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!