inner2outer
反转表或时间表中嵌套的表格层次结构
说明
T2 = inner2outer(
在 T1
)T1
中查找本身就是表或时间表的变量。它返回 T2
,这个表或时间表中也包含嵌套的表或时间表作为变量。T2
中的变量名称取自 T1
的嵌套表或时间表中的变量名称。然后,inner2outer
将 T2
的嵌套表或时间表中的变量进行适当的重组。如果 T1
中的变量不是表或时间表,则这些变量在 T2
中不变。
例如,如果 T1
有两个分别名为 A
和 B
的变量,并且它们均为包含名为 X
、Y
和 Z
的变量的表,则输出表 T2
有三个变量。T2
的变量命名为 X
、Y
和 Z
,每个变量都是一个表,其中包含两个分别名为 A
和 B
的变量。表变量 T1.A.X
和 T1.B.X
重新分组为 T2.X.A
和 T2.X.B
。T1
中的其他表变量按照相同的模式在 T2
中重新分组。
示例
反转嵌套表
加载并显示时间表 T1
,其中嵌套了包含股票信息的表。嵌套的表 AAPL
和 MSFT
是 T1
的变量。每个嵌套的表包含一家公司在交易开始和结束时的股票价格和成交量。
load nestedTables
T1
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
要将 Open
、Close
和 Volume
变量组合到各自的嵌套表中,请使用 inner2outer
函数。
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
将每支股票的数据分组到 T2
的嵌套表中之后,有些计算会更方便。例如,您可以使用 T2.Volume
对所有股票的成交量进行归一化处理。
使用 T2
的 Variables
属性将 T2.Volume
转换为矩阵。然后从 T2.Volume
中减去 T2.Volume
的均值,并以矩阵形式返回结果。
normVolume = T2.Volume.Variables - mean(T2.Volume.Variables)
normVolume = 28.1213 5.5193 -21.1397 -15.2217 -6.9817 9.7023
您也可以对嵌套的表使用表函数。使用 varfun
函数计算所有股票的平均收盘价,并在一个表中返回均值。
meanClose = varfun(@mean,T2.Close)
meanClose = 1x2 table mean_AAPL mean_MSFT _________ _________ 78.596 84.297
输入参数
T1
— 输入表
表 | 时间表
输入表,指定为表或时间表。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持基于线程的环境。有关详细信息,请参阅Run MATLAB Functions in Thread-Based Environment。
版本历史记录
在 R2018a 中推出
MATLAB 命令
您点击的链接对应于以下 MATLAB 命令:
请在 MATLAB 命令行窗口中直接输入以执行命令。Web 浏览器不支持 MATLAB 命令。
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)