Sort matrix based on values in the first row from small to large

Hi,
I have a matrix M
M =
39 93 143 64 36
1 2 3 4 5
I would like to sort the matrix M by values in the top row from small to large and expecting the integers in the buttom row also move accordingly, leading to something like
newM = 36 39 64 93 143
5 1 4 2 3
I mean I could transpose the matrix and do it using 'sortrows' then transpose back.
I am just wondering whether there is a more straight forward way of achieving it?

댓글 수: 1

I'm curious what problems there are with sortrows. Mind sharing why you're looking for an alternative?

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

 채택된 답변

Adam Danz
Adam Danz 2019년 11월 12일
편집: Adam Danz 2019년 11월 13일
newM = sortrows(m.').';
That's pretty straightforward ;)

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Shifting and Sorting Matrices에 대해 자세히 알아보기

질문:

2019년 11월 12일

댓글:

2019년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by