table.table2cell
table: C = table2cell (tbl)
Converts a table to a cell array.
Each variable in tbl becomes a column of cells in the output C. Multicolumnar variables are returned in a single column with each cell element containing a row vector.
The size of the returned cell array, C, is the same as the input table, tbl. The output C does not include any of the table’s properties. This also applies to row names.
Compatibility Notes:
Variables of types categorical, calendarDuration,
datetime, duration and string are returned as
in their printed representation as character vectors. To revert them to
their original class type you can parse the cell elements to the
respective object constructor.
Nested tables are handled as multicolumnar variables only if they contain data types, which can be converted to homogeneous array, i.e. numerical logical values. Other data types will result to a warning due to implicit conversion from numeric to char and the returned values will not contain all values from the nested table.
Source Code: table
table2cell unpacks a table into a cell array with one cell per element, preserving heterogeneous variable types that table2array could not merge.
LastName = {'Sanchez'; 'Johnson'; 'Li'};
Age = [38; 43; 38];
Smoker = logical ([1; 0; 1]);
T = table (LastName, Age, Smoker)
T =
3x3 table
LastName Age Smoker
___________ ___ ______
{'Sanchez'} 38 true
{'Johnson'} 43 false
{'Li' } 38 true
C = table2cell (T)
C =
3x3 cell array
{'Sanchez'} {[38]} {[1]}
{'Johnson'} {[43]} {[0]}
{'Li' } {[38]} {[1]}
Each column of the cell array corresponds to one table variable, so the result is independent of the original variable types.
class (C)
ans = cell