Filter löschen
Filter löschen

How to sort the components of a vector?

1 Ansicht (letzte 30 Tage)
Andre Ged
Andre Ged am 19 Feb. 2016
Bearbeitet: Stephen23 am 19 Feb. 2016
How can i sort the components of a vector in increasing order?

Akzeptierte Antwort

Stephen23
Stephen23 am 19 Feb. 2016
Bearbeitet: Stephen23 am 19 Feb. 2016
  2 Kommentare
Andre Ged
Andre Ged am 19 Feb. 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 am 19 Feb. 2016
Bearbeitet: Stephen23 am 19 Feb. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by