Matlab中table2cell函数使用

目录

语法

说明

示例

将表转换为元胞数组


        table2cell函数是将表转换为元胞数组。

语法

​C = table2cell(T)

        输入表,指定为表。如果 T 为 m×n 表,则 C 为 m×n 元胞数组。

说明

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

示例

将表转换为元胞数组

        创建一个包含五行和三个变量的表 T

T = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],...
    [124 93;109 77; 125 83; 117 75; 122 80],...
    'VariableNames',{'Gender' 'Age' 'BloodPressure'},...
    'RowNames',{'Smith' 'Johnson' 'Williams' 'Jones' 'Brown'})
T=5×3 table
                Gender    Age    BloodPressure
                ______    ___    _____________

    Smith         M       38      124     93  
    Johnson       M       43      109     77  
    Williams      F       38      125     83  
    Jones         F       40      117     75  
    Brown         F       49      122     80  

        将 T 转换为元胞数组。

C = table2cell(T)
C=5×3 cell array
    {[M]}    {[38]}    {1x2 double}
    {[M]}    {[43]}    {1x2 double}
    {[F]}    {[38]}    {1x2 double}
    {[F]}    {[40]}    {1x2 double}
    {[F]}    {[49]}    {1x2 double}

        C为 5×3 元胞数组。将表属性 T.Properties.VariableNames 与 C 垂直串联,以包含元胞数组的列标题。

[T.Properties.VariableNames;C]
ans=6×3 cell array
    {'Gender'}    {'Age'}    {'BloodPressure'}
    {[M     ]}    {[ 38]}    {1x2 double     }
    {[M     ]}    {[ 43]}    {1x2 double     }
    {[F     ]}    {[ 38]}    {1x2 double     }
    {[F     ]}    {[ 40]}    {1x2 double     }
    {[F     ]}    {[ 49]}    {1x2 double     }

T.Properties.VariableNames 为字符向量元胞数组。

猜你喜欢

转载自blog.csdn.net/jk_101/article/details/110938959