Borrar filtros
Borrar filtros

sort rows of a matrix based on their maximum value

10 visualizaciones (últimos 30 días)
pavlos
pavlos el 11 de Sept. de 2013
Hello,
Consider a 100x10 matrix.
Each 1x10 row has a maximum value.
How can I sort the rows of the matrix in ascending order based only on their maximum value?
Thank you very much.
Best,
Pavlos

Respuesta aceptada

Jan
Jan el 11 de Sept. de 2013
A = rand(100, 10);
maxA = max(A, [], 2);
[dummy, index] = sort(maxA);
B = A(index, :);
  1 comentario
Simon
Simon el 11 de Sept. de 2013
Great! Better solution than mine!
Side note: you may use "~" instead of "dummy".

Iniciar sesión para comentar.

Más respuestas (2)

Azzi Abdelmalek
Azzi Abdelmalek el 11 de Sept. de 2013
Editada: Azzi Abdelmalek el 11 de Sept. de 2013
Edit2
[ii,ii]=sort(max(A'))
BB=A(ii,:)

Simon
Simon el 11 de Sept. de 2013
A=randi(100,10,5);
for n = 1:size(A, 1)
B(n,:) = sort(A(n,:));
end

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