Rearranging tables based on elements

2 ビュー (過去 30 日間)
atom51
atom51 2022 年 3 月 17 日
回答済み: Scott MacKenzie 2022 年 3 月 17 日
I have a dataset with for 4 students with their grades over 6 months generated as follows:
month ranks grades
1 2 3 4 1 2 3 4
---------- ---------- ----------- -------- ------ ------ ------- --------
1 st_A st_B st_C st_D 98 95 87 80
2 st_A st_B st_C st_D 100 93 89 81
3 st_A st_C st_B st_D 99 95 90 80
4 st_C st_A st_B st_D 100 99 95 70
5 st_A st_C st_D st_B 98 95 90 80
6 st_A st_C st_B st_D 94 90 88 84
is there a simple way to rearrange the table such that instead of having the ranks as headers, the students become the headers and their grades are mapped accordingly ?? so that the output is as follows
month students
st_A st_B st_C st_D
---------- ---------- ----------- --------
1 98 95 87 80
2 100 93 89 81
3 99 90 95 80
4 99 95 100 70
5 98 80 95 90
6 94 88 90 84

回答 (1 件)

Scott MacKenzie
Scott MacKenzie 2022 年 3 月 17 日
For tables, an effective way to "transpose" (switch rows with columns, including variable names) is using the rows2vars function. You need to be working with R2018a or later, however. There are examples in the documentation.

カテゴリ

Help Center および File ExchangeTables についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by