how to reverse "sort"

89 次查看(过去 30 天)
Niki
Niki 2011-9-10
For example we have a row like
m=[1 6 2 8 9] [Y,I] = sort(m)
then it gives you
Y =
1 2 6 8 9
I =
1 3 2 4 5
But I would like to sort them from big number to small

采纳的回答

Joan Puig
Joan Puig 2011-9-10
Hi,
There is an extra optional argument that will do that:
>> m=[1 6 2 8 9]; [Y,I] = sort(m,'descend')
Y =
9 8 6 2 1
I =
5 4 2 3 1
>>
  1 个评论
Saurabh saini
Saurabh saini 2021-10-18
thanks for your answer it is very helpful to save time sir

请先登录,再进行评论。

更多回答(1 个)

Wayne King
Wayne King 2011-9-10
Hi, have you read the documentation for sort()?
m = [1 6 2 8 9];
[Y,I] = sort(m,'descend');
Wayne

类别

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