table

Methods

Method Reference: table.table2array

table: A = table2array (tbl)

Converts a table to an array.

A = table2array (tbl) places the variables of tbl side by side and joins them into one array A, as concatenation with [] joins them in MATLAB. A multicolumn variable gives as many columns. The row names and every other property of tbl are left out. tbl{:,:} and tbl.Variables return the same array.

The variables join as follows:

  • Numeric and logical variables join as numbers do. An integer type takes precedence over single, double and logical, the leftmost integer type over any other integer type, single over double, and double over logical. Values outside the range of the resulting integer type are clipped to its limits.
  • A numeric variable beside a char variable becomes the characters of its values. A logical variable does not join a char variable.
  • Cell variables join only with other cell variables.
  • A duration variable joins double and logical variables, whose values count days, and a calendarDuration variable joins all three.
  • categorical variables join only if all or none of them are ordinal, and datetime variables only if all or none of them have a time zone. Structures join only with the same fields, and nested tables only with different variable names.
  • A missing variable joins double, single, categorical, datetime, duration and calendarDuration variables, as the missing value of their type.

Where the variables cannot form one array, A is the cell array that table2cell returns; MATLAB raises an error instead.

The exception is a string variable. Numeric, logical, char, cell and missing variables beside it are converted to strings, and A is a string array instead of a cell array. Each row of a char variable becomes one string, each cell one string, and a logical value the string "true" or "false".

Source Code: table

table2array horizontally concatenates the variables into a single array, so it is meant for tables whose variables share a common type. Multi-column variables keep all their columns, so the result can be wider than the table.

 Age = [38; 43; 40];
 BloodPressure = [124, 93; 109, 77; 117, 75];
 T = table (Age, BloodPressure)
T =
  3x2 table

    Age    BloodPressure    
    ___    _____________    

     38        124    93    
     43        109    77    
     40        117    75
 A = table2array (T)
A =

    38   124    93
    43   109    77
    40   117    75

The 3-by-2 table becomes a 3-by-3 numeric matrix, because BloodPressure contributes two columns.

 size (A)
ans =

   3   3