How to sort the components of a vector?

5 vues (au cours des 30 derniers jours)
Andre Ged
Andre Ged le 19 Fév 2016
Modifié(e) : Stephen23 le 19 Fév 2016
How can i sort the components of a vector in increasing order?

Réponse acceptée

Stephen23
Stephen23 le 19 Fév 2016
Modifié(e) : Stephen23 le 19 Fév 2016
  2 commentaires
Andre Ged
Andre Ged le 19 Fév 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 le 19 Fév 2016
Modifié(e) : Stephen23 le 19 Fév 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Shifting and Sorting Matrices dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by