Borrar filtros
Borrar filtros

Sorting matrices

1 visualización (últimos 30 días)
Jason
Jason el 6 de Abr. de 2011
so I have two matrices:
A = [4 6 3 2 9 0 1 5 7 8]
B = [6 5 2 4 0 8 3 7 4 9]
I want to sort matrix A in ascending order, but I want B to correspond with the sorting so that the column match. so if I sort(A), I want B to look like this:
A = [0 1 2 3 4 5 6 7 8 9]
B = [8 3 4 2 6 7 5 4 9 0]
Matrix B can have more than one rows. B is not to be sorted, it just follow the sorting of matrix A. A and B can be in one matrix so as long as I can sort the first row, all the following rows will follow. I would like some ideas about doing this. Thanks.

Respuesta aceptada

Matt Fig
Matt Fig el 6 de Abr. de 2011
[As,I] = sort(A);
Bs = B(I);
To sort along the rows, use the dim argument to SORT.
  5 comentarios
Jason
Jason el 6 de Abr. de 2011
Got it now. Thanks.
Mohamed Helmy
Mohamed Helmy el 26 de Abr. de 2011
Thanksssssssss

Iniciar sesión para comentar.

Más respuestas (1)

Tim Zaman
Tim Zaman el 6 de Abr. de 2011
Append A to B so that
i believe the code is C=[A;B] so that:
C = [4 6 3 2 9 0 1 5 7 8;
6 5 2 4 0 8 3 7 4 9]
Then you say "sort(C,1)" so that the sorting is done for the first column
Have fun
PS makeup and layout in this textbox is awful
  1 comentario
Sean de Wolski
Sean de Wolski el 6 de Abr. de 2011
What about it is awful?

Iniciar sesión para comentar.

Categorías

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

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by