Restructuring a matrix based on an index
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
I have a 60x12 matrix in a table format (with column headers), where the first three columns are identification indices: site (1, 2, 3), species (1, 2, 3), and individual ID (1, 2, ...10), while the remaining nine columns are measured data (height, diameter etc.). I want to restructure the matrix so that site and species remain as columns, whereas the individual ID (within each combination of site and species) is used as an index in the nine columns with measured variables (which would turn into 9 * 10). So instead of height, diameter etc., I would get height_ID1, ... height_ID10, diameter_ID1, ... diameter_ID10 etc. What complicates things (perhaps) is that:
1) for each site and species, individual IDs are 1, 2, ...10. I want to unstack data based on individual IDs within each combination of species and site (not aggregate them together), i.e. keep all combinations of site and species in columns 1 and 2,
2) in some cases, there are two or more rows with the same combination of site, species and individual ID, e.g. in case of diameter which was measured in two directions, or other parameters which were sampled a few times.
Is there an easy function which will let me restructure my data in such a way, and adjust variable names accordingly (by combining original variable name with ID+number, i.e. height_ID1)?
Many thanks in advance for help!
3 Commenti
Cris LaPierre
il 9 Giu 2023
There is not an option for that. A workaround might be to create a new table variable that does create a unique value for each row you want to keep, and use that to unstack your table.
Risposte (0)
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!