table2array
将表转换为同构数组
说明
示例
将数值数据的表转换为数组
创建一个包含数值数据的表 T
。
T = table([1;2;3],[2 8; 4 10; 6 12],[3 12 21; 6 15 24; 9 18 27],... 'VariableNames',["One" "Two" "Three"])
T=3×3 table
One Two Three
___ _______ _____________
1 2 8 3 12 21
2 4 10 6 15 24
3 6 12 9 18 27
将表 T
转换为数组。
A = table2array(T)
A = 3×6
1 2 8 3 12 21
2 4 10 6 15 24
3 6 12 9 18 27
A
中包含变量 Two
的两列以及变量 Three
的三列。
将表的数值子集转换为数组
定义表的数值子集以转换为数组。
创建第一个变量包含非数值数据的表。
T = table(categorical(["Y";"Y";"N";"N";"F"]),[38;43;38;40;49],... [71;69;64;67;64],[176;163;131;133;119],... 'VariableNames',["Smoker" "Age" "Height" "Weight"])
T=5×4 table
Smoker Age Height Weight
______ ___ ______ ______
Y 38 71 176
Y 43 69 163
N 38 64 131
N 40 67 133
F 49 64 119
将 T(:,2:4)
转换为数组。
A = table2array(T(:,2:4))
A = 5×3
38 71 176
43 69 163
38 64 131
40 67 133
49 64 119
A
不包含变量 Smoker
的数据。
将包含三维变量的表转换为数组
创建一个包含两行和三个变量的表 T
,其中每个变量都具有三个维度。
T = table(ones(2,1,3),2*ones(2,2,3),3*ones(2,3,3),... 'VariableNames',["One" "Two" "Three"])
T=2×3 table
One Two Three
____________ ____________ ____________
1x1x3 double 1x2x3 double 1x3x3 double
1x1x3 double 1x2x3 double 1x3x3 double
该表的大小为 2×3。
将表 T
转换为数组。
A = table2array(T)
A = A(:,:,1) = 1 2 2 3 3 3 1 2 2 3 3 3 A(:,:,2) = 1 2 2 3 3 3 1 2 2 3 3 3 A(:,:,3) = 1 2 2 3 3 3 1 2 2 3 3 3
A
的大小为 2×6×3。
输入参数
T
— 输入表
表 | 时间表
输入表,指定为表或时间表。T
中的所有变量都必须具有适合水平串联的大小和数据类型。具体而言,维度大于 2
的所有变量的大小必须匹配。
如果
T
是一个每个变量具有一列的m
×n
表或时间表,则每个变量都将成为A
中的一列,并且A
是一个m
×n
数组。如果
T
中的变量包含多列,这些变量将成为A
中的多列,并且A
的大小大于T
的大小。如果
T
包含二维以上的变量,则A
的维数与变量维数相同。
提示
table2array
水平串联T
中的变量以创建A
。如果T
中的变量为元胞数组,则table2array
不会串联其内容,并且A
也为元胞数组,等效于table2cell(T)
。要创建包含元胞数组变量的内容的数组,请使用cell2mat(table2cell(T))
。table2array(T)
等效于T{:,:}
。
算法
如果 T
包含的变量具有适合水平串联的不同数据类型,table2array
将会创建一个具有主导数据类型的同构数组 A
。例如,如果 T
包含 double
和 single
数值数据,table2array(T)
将返回数据类型为 single
的数组。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
用法说明和限制:
在生成的代码中,使用该函数时,表变量名称必须为常量。有关详细信息,请参阅 表的代码生成 (MATLAB Coder) 和 Table Limitations for Code Generation (MATLAB Coder)。
分布式数组
使用 Parallel Computing Toolbox™ 在集群的组合内存中对大型数组进行分区。
此函数完全支持分布式数组。有关详细信息,请参阅Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox)。
版本历史记录
在 R2013b 中推出
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)