Categories &

Functions List

Function Reference: cell2table

datatypes: tbl = cell2table (C)
datatypes: tbl = cell2table (C, Name, Value)

Convert a cell array to a table.

tbl = cell2table (C) converts the 2-D cell array C to the table tbl, where the contents of each column of C becomes a variable in tbl. The contents of each column are concatenated into their common data type (i.e. if a column of C contains explicitly double numbers, then the corresponding variable in tbl is of the same type), otherwise they are added as a column of cells.

tbl = cell2table (C, Name, Value) specifies optional parameters for creating the table tbl with the following Name-Value paired arguments.

NameValue
'VariableNames'A cell array of character vectors or a string array defining the variable names of tbl. The names must be valid variable names and unique.
'RowNames'A cell array of character vectors or a string array defining the row names of tbl. The names must be unique but not necessarily valid variable names.
'DimensionNames'A cell array of character vectors or a string array defining the dimension names of tbl. The names must be unique and not in conflict with variable names. By default, dimension names are 'Row', 'Variables'.

Source Code: cell2table

See also: array2table, struct2table, table

Source Code: cell2table

Example: 1

cell2table turns a 2-D cell array into a table, one column per variable. Unlike a matrix, the cell columns may hold different types.

 C = {'Sanchez', 38, true; 'Johnson', 43, false; 'Li', 38, true};
 cell2table (C, 'VariableNames', {'LastName', 'Age', 'Smoker'})
ans =
  3x3 table

     LastName      Age    Smoker    
    ___________    ___    ______    

    {'Sanchez'}     38    true      
    {'Johnson'}     43    false     
    {'Li'     }     38    true