This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.


Convert table to cell array


C = table2cell(T)



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


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 = 5x3 cell array
    {[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.

ans = 6x3 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 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

Was this topic helpful?