How do I sort all the columns of a table based on the first column?

26 ビュー (過去 30 日間)
Bhavishey Thapar
Bhavishey Thapar 2022 年 7 月 20 日
コメント済み: Bhavishey Thapar 2022 年 7 月 20 日
I am trying to sort a table which contains datetime values in the first column and corresponding temperatures in the second column. I want to sort the table by datetime without affecting the relationship between datetime and the temperatures.
For example, if a table looks like this:
Date Temperature
2022-06-01 21
2022-05-29 18
2022-05-21 19
2022-06-04 25
2022-06-02 22
I want it to be sorted like below:
Date Temperature
2022-05-21 19
2022-05-29 18
2022-06-01 21
2022-06-02 22
2022-06-04 25
How do I achieve this?

採用された回答

Stephen23
Stephen23 2022 年 7 月 20 日
Where T is your table:
T = sortrows(T,'Date')
  2 件のコメント
Stephen23
Stephen23 2022 年 7 月 20 日
Demonstration:
Date = datetime(2022,[6;5;5;6;6],[1;29;21;4;2]);
Temperature = [21;18;19;25;22];
T = table(Date,Temperature)
T = 5×2 table
Date Temperature ___________ ___________ 01-Jun-2022 21 29-May-2022 18 21-May-2022 19 04-Jun-2022 25 02-Jun-2022 22
T = sortrows(T,'Date')
T = 5×2 table
Date Temperature ___________ ___________ 21-May-2022 19 29-May-2022 18 01-Jun-2022 21 02-Jun-2022 22 04-Jun-2022 25
Bhavishey Thapar
Bhavishey Thapar 2022 年 7 月 20 日
Thank you!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by