Borrar filtros
Borrar filtros

How to sort the components of a vector?

1 visualización (últimos 30 días)
Andre Ged
Andre Ged el 19 de Feb. de 2016
Editada: Stephen23 el 19 de Feb. de 2016
How can i sort the components of a vector in increasing order?

Respuesta aceptada

Stephen23
Stephen23 el 19 de Feb. de 2016
Editada: Stephen23 el 19 de Feb. de 2016
  2 comentarios
Andre Ged
Andre Ged el 19 de Feb. de 2016
Thank you! Another little question. If every elements of that vector refers to a row of a matrix, is there a way to sort the rows of this matrix like the vector? I hope it is well explained!
Stephen23
Stephen23 el 19 de Feb. de 2016
Editada: Stephen23 el 19 de Feb. de 2016
Use the second output of sort as indices for the matrix rows:
[newvec,idx] = sort(vec)
out = mat(idx,:)
This will sort the matrix rows into the same order as the vector is sorted.

Iniciar sesión para comentar.

Más respuestas (0)

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