Main Content

table2cell

Convert table to cell array

Description

C = table2cell(T) converts the table or timetable, T, to a cell array, C. Each variable in T becomes a column of cells in C.

The output C does not include the table properties in T.Properties.

  • If T is a table with row names, then C does not include the row names.

  • If T is a timetable, then C does not include the row times.

example

Examples

collapse all

Create a table, T, with five rows and three variables.

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  

Convert T to a cell array.

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 is a 5-by-3 cell array.

Vertically concatenate the table property, T.Properties.VariableNames, with C to include column headings for the cell array.

[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 stores the variable names as a cell array of character vectors, even when the names were previously assigned from a string array.

Input Arguments

collapse all

Input table, specified as a table or timetable.

If T is an m-byn table or timetable, then C is an m-by-n cell array.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2013b