array2table

Converts a matrix or array into a table.

Category: Language Fundamentals > Data Types

Syntax

T = array2table(A)

Makes one table variable for each column of A, named Var1, Var2, and so on.

T = array2table(A, 'VariableNames', names)

Names the variables.

T = array2table(A, 'RowNames', rows)

Labels the rows.

Description

All columns share the class of the source array. After conversion the data can be accessed by name (T.x), summarized and joined with other tables. Use table2array to go back.

Input arguments

A
2-D array, numeric, logical, char or any type that can be split by column.
'VariableNames'
Cell array or string array with one name per column.
'RowNames'
Cell array or string array with one name per row.

Output arguments

T
Table with size(A,1) rows and size(A,2) variables, all of the class of A.

Example

Name columns and rows

A = [1 2; 3 4];
T = array2table(A, 'VariableNames', {'x', 'y'}, 'RowNames', {'r1', 'r2'})
Output
T = 2×2 table

          x    y
          _    _

    r1    1    2
    r2    3    4

See also

table table2array cell2table struct2table array2timetable