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 CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by