Integrating Indices
Mostrar comentarios más antiguos
Hello,
I have taken the matrix below and sorted it ascending by row:
(Original) A=[1 4 5; 3 -1 8; 12 7 9; 4 10 -5];
(Sorted By Row) B=[1 4 5; -1 3 8; 7 9 12; -5 4 10];
I would like to have the indices of the original matrix appear in the locations of the sorted matrix. For this case it would look like this.
(Original) A=[1 2 3; 1 2 3; 1 2 3; 1 2 3];
(Sorted By Row) B=[1 2 3; 2 1 3; 2 3 1; 3 1 2];
I have tried several different methods but with no luck. Any assistance is appreciated
Thanks
1 comentario
zohar
el 21 de Feb. de 2011
Hi Daniel
Give us some code and use the code formatting.
Respuesta aceptada
Más respuestas (2)
Daniel
el 21 de Feb. de 2011
1 comentario
Oleg Komarov
el 21 de Feb. de 2011
Have you tried Walter's solution?
Daniel
el 21 de Feb. de 2011
2 comentarios
Oleg Komarov
el 21 de Feb. de 2011
A=[ 4 3; 8 4;-1 -5; 2 7];
[sorted_A, sort_indexes] = sort(A,2)
gives exactly the second matrix...
Daniel
el 21 de Feb. de 2011
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!