table2cell
Convert table to cell array
Syntax
Description
C = table2cell(
converts the table or timetable,
T
)T
, to a cell array, C
. Each variable in
T
becomes a column of cells in C
.
The output C
does not include the table properties in
T.Properties
.
If
T
is a table with row names, thenC
does not include the row names.If
T
is a timetable, thenC
does not include the row times.
Examples
Convert Table to Cell Array
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 = table2cell(T)
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
T
— Input table
table | timetable
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
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
This function fully supports tall arrays. For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
This function fully supports code generation. For more information, see Code Generation for Tables (MATLAB Coder).
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
Distributed Arrays
Partition large arrays across the combined memory of your cluster using Parallel Computing Toolbox™.
This function fully supports distributed arrays. For more information, see Run MATLAB Functions with Distributed Arrays (Parallel Computing Toolbox).
Version History
Introduced in R2013b
See Also
Apri esempio
Si dispone di una versione modificata di questo esempio. Desideri aprire questo esempio con le tue modifiche?
Comando MATLAB
Hai fatto clic su un collegamento che corrisponde a questo comando MATLAB:
Esegui il comando inserendolo nella finestra di comando MATLAB. I browser web non supportano i comandi MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)