Main Content

table2cell

将表转换为元胞数组

说明

示例

C = table2cell(T) 将表或时间表 T 转换为元胞数组 CT 中的每个变量都会成为 C 中的元胞列。

输出 C 不包括 T.Properties 中的表属性。

  • 如果 T 是包含行名称的表,则 C 不包含行名称。

  • 如果 T 是时间表,则 C 不包括行时间。

示例

全部折叠

创建一个包含五行和三个变量的表 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.VariableNamesC 垂直串联,以包含元胞数组的列标题。

[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 将变量名称存储为字符向量元胞数组,即使这些名称以前是从字符串数组中指定的也是如此。

输入参数

全部折叠

输入表,指定为表或时间表。

如果 Tm×n 表或时间表,则 Cm×n 元胞数组。

扩展功能

基于线程的环境
使用 MATLAB® backgroundPool 在后台运行代码或使用 Parallel Computing Toolbox™ ThreadPool 加快代码运行速度。

版本历史记录

在 R2013b 中推出