table2cell
Convert table to cell array
Syntax
Description
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
Input table, specified as a table.
If T
is an m
-byn
table,
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).
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
See Also
Abrir ejemplo
Tiene una versión modificada de este ejemplo. ¿Desea abrir este ejemplo con sus modificaciones?
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de 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)