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
为 m
×n
表或时间表,则 C
为 m
×n
元胞数组。
扩展功能
table2cell
函数完全支持 tall 数组。有关详细信息,请参阅 tall 数组。
此函数完全支持代码生成。有关详细信息,请参阅表的代码生成 (MATLAB Coder)。
基于线程的环境
使用 MATLAB® backgroundPool
在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool
加快代码运行速度。
此函数完全支持分布式数组。有关详细信息,请参阅使用分布式数组运行 MATLAB 函数 (Parallel Computing Toolbox)。
版本历史记录
在 R2013b 中推出
另请参阅
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)