主要内容

inner2outer

Invert nested table-in-table hierarchy in tables or timetables

Description

example

T2 = inner2outer(T1)finds the variables inT1that are themselves tables or timetables. It returnsT2, a table or timetable that also contains nested tables or timetables as variables. The names of the variables inT2are taken from the names of the variables inside the nested tables or timetables ofT1。然后,inner2outerregroups variables in the nested tables or timetables ofT2appropriately, as shown in the diagram. IfT1has variables that are not tables or timetables, then those variables are unaltered inT2

Examples

collapse all

Load and display a timetable,T1, that has nested tables containing stock information. The nested tablesappleMSFTare the variables ofT1。Each nested table has the stock prices at the open and close of trading, and the volume, for a different company.

loadnestedTablesT1
T1 = 3x2 timetable Dates AAPL MSFT Open Close Volume Open Close Volume ___________ __________________________ __________________________ 01-Jan-2017 64.539 71.704 107.17 66.429 91.77 78.7 01-Feb-2017 101.53 87.619 57.909 72.984 84.629 57.959 01-Mar-2017 60.381 76.464 72.067 78.127 76.492 82.883

To group theOpen,Close, 和Volumevariables together in nested tables of their own, use theinner2outerfunction.

T2 = inner2outer(T1)
T2 = 3x3 timetable Dates Open Close Volume AAPL MSFT AAPL MSFT AAPL MSFT ___________ ________________ ________________ ________________ 01-Jan-2017 64.539 66.429 71.704 91.77 107.17 78.7 01-Feb-2017 101.53 72.984 87.619 84.629 57.909 57.959 01-Mar-2017 60.381 78.127 76.464 76.492 72.067 82.883

Some calculations are more convenient with data from each stock grouped in the nested tables ofT2。例如,您可以使用T2.Volume

Use the变量property ofT2to convertT2.Volumeinto a matrix. Then subtract the mean ofT2.VolumefromT2.Volume和return the result as a matrix.

normVolume = T2.Volume.Variables - mean(T2.Volume.Variables)
normVolume = 28.1213 5.5193 -21.1397 -15.2217 -6.9817 9.7023

You also can use table functions on the nested tables. Calculate the mean closing price of all stocks using thevarfun功能,返回表中的均值。

MENECLOSE = VARFUN(@Mean,T2.Close)
meanClose = 1x2 table mean_AAPL mean_MSFT _________ _________ 78.596 84.297

Input Arguments

collapse all

输入表, specified as a table or timetable.

Extended Capabilities

他的版本tory

Introduced in R2018a