How can I sort a matrix elementwise ?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Gayan Lankeshwara
el 21 de Oct. de 2019
Comentada: Gayan Lankeshwara
el 21 de Oct. de 2019
Hi, I need to sort a matrix elementwise and get the results to a single vector without losing the index of each element.
For example,
A = [3, 4 ; 6, 2]
The sorted vector should be ,
B = [2;3;4;6]
without losing the information of each and every element in the original matrix.
Thank you.
0 comentarios
Respuesta aceptada
Andrei Bobrov
el 21 de Oct. de 2019
A = [3, 4 ; 6, 2];
[m,~] = size(A);
[B,i] = sort(A(:));
index = [mod(i-1,m) + 1, ceil(i/m)];
Ver también
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!