how to reverse "sort"

94 visualizaciones (últimos 30 días)
Niki
Niki el 10 de Sept. de 2011
Comentada: Saurabh saini el 18 de Oct. de 2021
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

Respuesta aceptada

Joan Puig
Joan Puig el 10 de Sept. de 2011
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 comentario
Saurabh saini
Saurabh saini el 18 de Oct. de 2021
thanks for your answer it is very helpful to save time sir

Iniciar sesión para comentar.

Más respuestas (1)

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

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by