Borrar filtros
Borrar filtros

how to sort a matrix?

1 visualización (últimos 30 días)
Hugo Matias
Hugo Matias el 1 de Dic. de 2018
Editada: Stephan el 1 de Dic. de 2018
How do i do this:
before:
a=[3 9 5 7;
3 0 1 2;
11 2 0 9];
after:
a=[11 9 9 7;
5 3 3 2;
2 1 0 0;]

Respuestas (1)

Stephan
Stephan el 1 de Dic. de 2018
Editada: Stephan el 1 de Dic. de 2018
Hi,
try:
>> a = [3 9 5 7; 3 0 1 2; 11 2 0 9]
a =
3 9 5 7
3 0 1 2
11 2 0 9
>> b = reshape(fliplr(sort(reshape(a,1,[]))),4,3)'
b =
11 9 9 7
5 3 3 2
2 1 0 0
Best regards
Stephan

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