Rearranging tables based on elements

2 vues (au cours des 30 derniers jours)
atom51
atom51 le 17 Mar 2022
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

Réponses (1)

Scott MacKenzie
Scott MacKenzie le 17 Mar 2022
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.

Catégories

En savoir plus sur Tables dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by