table2cell

Convert table to cell array

Description

example

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

Examples

collapse all

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

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  

Convert T to a cell array.

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

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
    {'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 is a cell array of character vectors.

Input Arguments

collapse all

Input table, specified as a table.

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

Extended Capabilities

Introduced in R2013b