How to sort a data set for plotting

11 ビュー (過去 30 日間)
Jacob Davidson
Jacob Davidson 2018 年 11 月 30 日
コメント済み: Star Strider 2020 年 1 月 31 日
I have here two data sets, one I want to use as my X and the other the Y axis.
For the X, which is my TNF placeholder values below, I want to simply sort the data array from least to greatest. Which I already know how to do. The Y values, TPF, are also shown below and correlate specifically to the respective index of the TNF array.
TNF = [e, a, d, c, b]
TPF = [e, a, d, c, b]
Sorted, it looks like:
TNF = [a, b, c, d, e]
So how to I get the TPF values to sort with the TNF values and not independently from least to greatest?

採用された回答

Star Strider
Star Strider 2018 年 11 月 30 日
Ise the second output of the sort function to return the indices, then use those to map ‘TPF’:
TNF = ['e', 'a', 'd', 'c', 'b']
TPF = ['e', 'a', 'd', 'c', 'b']
[TNFsorted, idx] = sort(TNF);
TPFsorted = TPF(idx)
  4 件のコメント
Dav
Dav 2020 年 1 月 31 日
Thanks Star.
Star Strider
Star Strider 2020 年 1 月 31 日
@Dav — My pleasure!

サインインしてコメントする。

その他の回答 (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