Sort a matrix based on one row?

10 visualizaciones (últimos 30 días)
Umesh
Umesh el 22 de Abr. de 2013
Comentada: Stephen23 el 22 de Jun. de 2025
lets say we have a 3x3 matrix as
a= 2 5 3;
2 8 1;
4 1 9;
and I want this matrix sorted based on its 2nd row in ascending order i.e.
answer= 3 2 5;
1 2 8;
9 4 1;
Thank you for any help you can offer.

Respuestas (1)

Walter Roberson
Walter Roberson el 22 de Abr. de 2013
[temp, order] = sort(a(2,:));
answer = a(:,order);
  3 comentarios
Akira Agata
Akira Agata el 20 de Jun. de 2025
Another solution:
answer = sortrows(a', 2)';
Stephen23
Stephen23 el 22 de Jun. de 2025
answer = sortrows(a.', 2).';
Using transpose, rather than complex conjugate transpose.

Iniciar sesión para comentar.

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by