필터 지우기
필터 지우기

Sort data based on different column

조회 수: 3 (최근 30일)
Pallav Patel
Pallav Patel 2020년 4월 7일
편집: Peter O 2020년 4월 7일
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.

채택된 답변

Peter O
Peter O 2020년 4월 7일
편집: Peter O 2020년 4월 7일
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개)

카테고리

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