According to the documentation, Matlab's unstack
can take this table:
S=12×3 table
Storm Town Snowfall
_____ ____ ________
3 'T1' 0
3 'T3' 3
1 'T1' 5
3 'T2' 5
1 'T2' 9
1 'T3' 10
4 'T2' 12
2 'T1' 13
4 'T3' 15
2 'T3' 16
4 'T1' 17
2 'T2' 21
...and convert it into:
U = unstack(S,'Snowfall','Town')
U=4×4 table
Storm T1 T2 T3
_____ __ __ __
3 0 5 3
1 5 9 10
4 17 12 15
2 13 21 16
It seems reasonable to assume that the new columns are generated in alphabetic order. To assume this would be fine if one is manually manipulating data, but is a deal breaker for automated data processing if one cannot be 100% assured of the ordering of the columns. For example, if the Town
column was actually a numerical index, then the new column names would be automatically generated so as to be legitimate variable names, and the ordering would be the key piece of information linking the new columns back to the values in the Town
field. If one extracts U{:,2:end} for manipulation, the data could be all wrong unless one could be 100% sure of whatever the scheme is for ordering the new columns.
I actually create a new column in place of Town
containing a valid string, suffixed with the numerical index value. These become the new column headings. But the reality is, having to write extra code to assure that the columns appear in the right order is too much trouble. It cancels out the benefit of unstack, and I ended up just creating loops to build up the new columns one by one. Not efficient or elegant in terms of time and code. I am trying to find a way to reliably exploit unstack in the future.
I have already submitted feedback describing the criticality of this bit of information, but I don't expect a response back any time soon. Meanwhile, unstacking is such a useful function that I wonder whether anyone can weigh in about the advisability of assuming alphabetic ordering of the new columns?