Convert hom*ogeneous array to table
collapse all in page
Syntax
T = array2table(A)
T = array2table(A,Name,Value)
Description
example
T = array2table(A)
convertsthe m
-by-n
array, A
,to an m
-by-n
table, T
.Each column of A
becomes a variable in T
.
array2table
uses the input array name appended with the column number for the variable names in the table. If these names are not valid MATLAB® identifiers, array2table
uses names of the form 'Var1',...,'Var
, where N
'N
is the number of columns in A
.
example
T = array2table(A,Name,Value)
createsa table from an array, A
, with additional optionsspecified by one or more Name,Value
pair arguments.
For example, you can specify row names or variable names toinclude in the table.
Examples
collapse all
Convert Numeric Array to Table
Open Live Script
Create an array of numeric data.
A = [1 4 7; 2 5 8; 3 6 9]
Convert the array, A
, to a table.
T = array2table(A)
T=3×3 table A1 A2 A3 __ __ __ 1 4 7 2 5 8 3 6 9
The table has variable names that append the column number to the input array name, A
.
Convert Array to Table Including Variable Names
Open Live Script
Create an array of numeric data.
A = [1 12 30.48; 2 24 60.96; 3 36 91.44]
A = 3×3 1.0000 12.0000 30.4800 2.0000 24.0000 60.9600 3.0000 36.0000 91.4400
Convert the array, A
, to a table and include variable names.
T = array2table(A,... 'VariableNames',{'Feet','Inches','Centimeters'})
T=3×3 table Feet Inches Centimeters ____ ______ ___________ 1 12 30.48 2 24 60.96 3 36 91.44
Input Arguments
collapse all
A
— Input array
matrix
Input array, specified as a matrix.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
| char
| string
| struct
| cell
Complex Number Support: Yes
Name-Value Arguments
Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN
, where Name
is the argument name and Value
is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.
Before R2021a, use commas to separate each name and value, and enclose Name
in quotes.
Example: 'RowNames',{'row1','row2','row3'}
uses the row names, row1
, row2
, and row3
for the table, T
.
RowNames
— Row names for T
{}
(default) | cell array of character vectors | string array
Row names for T
, specified as the comma-separated pair consisting of 'RowNames'
and a cell array of character vectors or string array, whose elements are nonempty and distinct. The number of names must equal the number of rows, size(A,1)
.
Row names can have any Unicode® characters, including spaces and non-ASCII characters.
If you specify row names that have leading or trailing whitespace characters, then array2table
removes them from the row names.
VariableNames
— Variable names for T
cell array of character vectors | string array
Variable names for T
, specified as the comma-separated pair consisting of 'VariableNames'
and a cell array of character vectors or a string array, whose elements are nonempty and distinct. The number of names must equal the number of variables, size(A,2)
.
Variable names can have any Unicode characters, including spaces and non-ASCII characters.
DimensionNames
— Dimension names
two-element cell array of character vectors | two-element string array
Since R2021a
Dimension names, specified as a two-element cell array of character vectors or two-element string array whose elements are nonempty and distinct.
Dimension names can have any Unicode characters, including spaces and non-ASCII characters.
Before R2021a, you can specify dimension names only by setting the DimensionNames
property of the output.
Output Arguments
collapse all
Tips
If
A
is a cell array, usecell2table(A)
tocreate a table from the contents of the cells inA
.Each variable in the table is numeric or a cell array of charactervectors.array2table(A)
creates a table where eachvariable is a column of cells.
Extended Capabilities
Tall Arrays
Calculate with arrays that have more rows than fit in memory.
This function supports tall arrays with the limitations:
The 'RowNames'
name-value pair is not supported.
For more information, see Tall Arrays.
C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.
Usage notes and limitations:
In generated code, you must specify the
'VariableNames'
name-value pair argument when using this function. For more information, see Code Generation for Tables (MATLAB Coder) and Table Limitations for Code Generation (MATLAB Coder).
Thread-Based Environment
Run code in the background using MATLAB® backgroundPool
or accelerate code with Parallel Computing Toolbox™ ThreadPool
.
Version History
Introduced in R2013b
expand all
R2019b: Variable names can contain leading and trailing whitespace characters
Table and timetable variable names with leading or trailing whitespace characters are not modified.
In previous releases, leading and trailing whitespace characters were deleted from variable names when you specified them using the 'VariableNames'
name-value pair argument, or assigned them to the VariableNames
property.
To manually remove such characters, first use the strtrim function on the names, then assign them as variable names to the table or timetable.
See Also
table2array | cell2table | struct2table | table | isvarname
Topics
- Access Data in Tables
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
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:
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
- Deutsch
- English
- Français
- United Kingdom (English)
Contact your local office