How to sort the components of a vector?

1 回表示 (過去 30 日間)
Andre Ged
Andre Ged 2016 年 2 月 19 日
編集済み: Stephen23 2016 年 2 月 19 日
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 Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by