table2cell
将表转换为元胞数组
说明
示例
将表转换为元胞数组
创建一个包含五行和三个变量的表 T
。
T = table(categorical(["Y";"Y";"N";"N";"N"]),[38;43;38;40;49],... [124 93;109 77; 125 83; 117 75; 122 80],... 'VariableNames',["Smoker" "Age" "BloodPressure"],... 'RowNames',["Chang" "Brown" "Ruiz" "Lee" "Garcia"])
T=5×3 table
Smoker Age BloodPressure
______ ___ _____________
Chang Y 38 124 93
Brown Y 43 109 77
Ruiz N 38 125 83
Lee N 40 117 75
Garcia N 49 122 80
将 T
转换为元胞数组。
C = table2cell(T)
C=5×3 cell array
{[Y]} {[38]} {[124 93]}
{[Y]} {[43]} {[109 77]}
{[N]} {[38]} {[125 83]}
{[N]} {[40]} {[117 75]}
{[N]} {[49]} {[122 80]}
C
为 5×3 元胞数组。
将表属性 T.Properties.VariableNames
与 C
垂直串联,以包含元胞数组的列标题。
[T.Properties.VariableNames;C]
ans=6×3 cell array
{'Smoker'} {'Age'} {'BloodPressure'}
{[Y ]} {[ 38]} {[ 124 93]}
{[Y ]} {[ 43]} {[ 109 77]}
{[N ]} {[ 38]} {[ 125 83]}
{[N ]} {[ 40]} {[ 117 75]}
{[N ]} {[ 49]} {[ 122 80]}
T.Properties.VariableNames
将变量名称存储为字符向量元胞数组,即使这些名称以前是从字符串数组中指定的也是如此。
输入参数
T
— 输入表
表 | 时间表
输入表,指定为表或时间表。
如果 T
为 m
×n
表或时间表,则 C
为 m
×n
元胞数组。
扩展功能
tall 数组
对行数太多而无法放入内存的数组进行计算。
此函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
C/C++ 代码生成
使用 MATLAB® Coder™ 生成 C 代码和 C++ 代码。
此函数完全支持代码生成。有关详细信息,请参阅表的代码生成 (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)