How to sort a column of data based on another?

5 ビュー (過去 30 日間)
Wolfgang McCormack
Wolfgang McCormack 2021 年 2 月 7 日
回答済み: Cris LaPierre 2021 年 2 月 7 日
Hi everyone, I have two columns of data. I wan to sort column A in theascending order and I want the corresponding values in column B be sorted as well according to A. How to do this in MATLAB?
Thanks!

採用された回答

Cris LaPierre
Cris LaPierre 2021 年 2 月 7 日
As shared in your original post tonight, look at sortrows.

その他の回答 (1 件)

weikang zhao
weikang zhao 2021 年 2 月 7 日
`[B,I] = sort(___) also returns a collection of index vectors for any of the previous syntaxes. I is the same size as A and describes the arrangement of the elements of A into B along the sorted dimension. For example, if A is a vector, then B = A(I).`
Record the index vector when sorting the array, then use the index vector to adjust another array.

カテゴリ

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