How to sort the components of a vector?

1 次查看(过去 30 天)
How can i sort the components of a vector in increasing order?

采纳的回答

Stephen23
Stephen23 2016-2-19
编辑:Stephen23 2016-2-19
  2 个评论
Andre Ged
Andre Ged 2016-2-19
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 2016-2-19
编辑:Stephen23 2016-2-19
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.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Shifting and Sorting Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by