table2cell - Convert table to cell array - MATLAB (original) (raw)

Main Content

Convert table to cell array

Syntax

Description

C = table2cell([T](#btx32ih-1-T)) converts the table or timetable,T, to a cell array, C. Each variable inT becomes a column of cells in C.

The output C does not include the table properties inT.Properties.

example

Examples

collapse all

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

T = table(categorical(["Y";"Y";"N";"N";"N"]),[38;43;38;40;49],... [124 93;109 77; 125 83; 117 75; 122 80],... 'VariableNames',["Smoker" "Age" "BloodPressure"],... 'RowNames',["Chang" "Brown" "Ruiz" "Lee" "Garcia"])

T=5×3 table Smoker Age BloodPressure ______ ___ _____________

Chang       Y       38      124     93  
Brown       Y       43      109     77  
Ruiz        N       38      125     83  
Lee         N       40      117     75  
Garcia      N       49      122     80  

Convert T to a cell array.

C=5×3 cell array {[Y]} {[38]} {[124 93]} {[Y]} {[43]} {[109 77]} {[N]} {[38]} {[125 83]} {[N]} {[40]} {[117 75]} {[N]} {[49]} {[122 80]}

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 {'Smoker'} {'Age'} {'BloodPressure'} {[Y ]} {[ 38]} {[ 124 93]} {[Y ]} {[ 43]} {[ 109 77]} {[N ]} {[ 38]} {[ 125 83]} {[N ]} {[ 40]} {[ 117 75]} {[N ]} {[ 49]} {[ 122 80]}

T.Properties.VariableNames stores the variable names as a cell array of character vectors, even when the names were previously assigned from a string array.

Input Arguments

collapse all

Input table, specified as a table or timetable.

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

Extended Capabilities

expand all

Thetable2cell function fully supports tall arrays. For more information, see Tall Arrays.

Version History

Introduced in R2013b