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

7 次查看(过去 30 天)
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?

采纳的回答

Adam Danz
Adam Danz 2019-11-12
编辑:Adam Danz 2019-11-13
newM = sortrows(m.').';
That's pretty straightforward ;)

更多回答(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