Order all the rows based on one row.

Hi!
I´ve searching for an answer but I didn´t find any, and before programming a super inefficient function I just wanted to be sure that there weren´t any prebuilt function to do this. So the question is:
How do you sort all the rows of a matrix based on one specific row. For example, based on the first row:
LENGTH =
723 1081 860
1 2 3
Sorted:
LENGTH =
723 860 1081
1 3 2
Thank you in advance!

 채택된 답변

the cyclist
the cyclist 2013년 5월 8일
편집: the cyclist 2013년 5월 8일

1 개 추천

Use the sortrows() command.
You are actually sorting columns, so you will need to transpose your array, then sort, then transpose back:
sorted_L = sortrows(L',1)'

댓글 수: 1

Angel Torrado
Angel Torrado 2013년 5월 8일
That worked!! I don´t know why I didn´t think on that... ¬¬
Thank you for the super fast answer!

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

추가 답변 (0개)

카테고리

도움말 센터File 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