array2table
datatypes: tbl = array2table (A)
datatypes: tbl = array2table (A, Name, Value)
Convert an array to a table.
tbl = array2table (A) converts the 2-D matrix A to
the table tbl, where each column of A becomes a variable in
tbl.
A can be any type of array supported by table, including a cell
array, as long they are constraint to 2 dimensions. However, in the case of
a cell array array2table does not extract the contents of its cells,
resulting to a table with each variable being a column of cells. Use
cell2table if you want to create a table from the contents of the
cells in A.
tbl = array2table (A, Name, Value) specifies
optional parameters for creating the table tbl with the following
Name-Value paired arguments.
| Name | Value |
|---|---|
'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: array2table
See also: cell2table, struct2table, table
Source Code: array2table
array2table wraps the columns of a matrix as table variables. Without names the variables are auto-labelled Var1, Var2, ...
A = [38, 71, 176; 43, 69, 163; 40, 67, 133]; array2table (A)
ans =
3x3 table
A1 A2 A3
__ __ ___
38 71 176
43 69 163
40 67 133
Supply 'VariableNames' (and optionally 'RowNames') to label the result as you convert — the columns of the matrix keep their order.
A = [38, 71; 43, 69; 40, 67];
array2table (A, 'VariableNames', {'Age', 'Height'}, ...
'RowNames', {'Li', 'Diaz', 'Brown'})
ans =
3x2 table
Age Height
___ ______
Li 38 71
Diaz 43 69
Brown 40 67