table.inner2outer
table: tblB = inner2outer (tblA)
Invert the nested hierarchy of nested tables in a table.
tblB = inner2outer (tblA) finds the variables in
tblA that are themselves tables (nested tables) and returns a table
tblB in which the inner and outer levels of nesting are transposed.
The variables of the nested tables in tblA become the variables of
tblB, and the variables of tblA that contain the nested
tables become the variables of the nested tables in tblB. Any
variable in tblA that is not a nested table is copied unaltered
into tblB.
For example, if tblA has two variables A and B that
both contain nested tables with the variables X and Y, then
tblB has two variables X and Y, each containing a
nested table with the variables A and B. As a result, the
table variables tblA.A.X and tblA.B.X are regrouped into
tblB.X.A and tblB.X.B, while tblA.A.Y and
tblA.B.Y are regrouped into tblB.Y.A and tblB.Y.B.
The new variables of tblB are the union of the variable names of the nested tables in tblA, placed at the position of the first nested table. An inner variable name shared by more than one nested table becomes a nested table in tblB grouping the corresponding variables; an inner variable name held by a single nested table becomes a plain variable carrying that column.
Source Code: table
inner2outer swaps the nesting of a table whose variables are themselves tables: the inner (nested) variables are lifted to the top level.
Inner = table ([1; 2; 3], [4; 5; 6], 'VariableNames', {'x', 'y'})
Inner =
3x2 table
x y
_ _
1 4
2 5
3 6
NT = table ([10; 20; 30], Inner, 'VariableNames', {'id', 'inner'})
NT =
3x2 table
id inner
__ ______________
x y
_____ _____
10 1 4
20 2 5
30 3 6
NT
NT =
3x2 table
id inner
__ ______________
x y
_____ _____
10 1 4
20 2 5
30 3 6
After inner2outer the nested x and y become ordinary variables.
inner2outer (NT)
ans =
3x3 table
id x y
__ _ _
10 1 4
20 2 5
30 3 6