Convert table to cell array
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 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.
[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
is a cell array of character vectors.
T
— Input tableInput table, specified as a table.
If T
is an m
-byn
table,
then C
is an m
-by-n
cell
array.
This function fully supports tall arrays. For more information, see Tall Arrays.
This function fully supports code generation. For more information, see Code Generation for Tables (MATLAB Coder).
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
You have a modified version of this example. Do you want to open this example with your edits?