combined sorting

12 visualizaciones (últimos 30 días)
Anand Anand
Anand Anand el 3 de Abr. de 2011
For ex;I have an array A=[1:4] and B=[12:19:2:20].If I sort B in descending order B=[20 19 12 2].I want the corresponding positions in A to be swapped as well...ie A=[4 2 1 3].How do I achieve that?

Respuesta aceptada

Matt Tearle
Matt Tearle el 3 de Abr. de 2011
[sortB,idx] = sort(B,'descend');
sortA = A(idx);
Or put the vectors into a matrix and use sortrows.
  2 comentarios
Anand Anand
Anand Anand el 3 de Abr. de 2011
thanks a lot Matt..I was actually writing a very long algorithm.-:)
Matt Tearle
Matt Tearle el 7 de Abr. de 2011
In MATLAB, that's generally a sign you're doing it wrong! :)

Iniciar sesión para comentar.

Más respuestas (0)

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