Documentation

table2array

Convert table to homogeneous array

Syntax

A = table2array(T)

Description

example

A = table2array(T)converts the table,T, to a homogeneous array,A.

Examples

collapse all

Create a table,T, consisting of numeric data.

T = table([1;2;3],[2 8; 4 10; 6 12],[3 12 21; 6 15 24; 9 18 27],...'VariableNames',{'One''Two''Three'})
T =3×3 tableOne Two Three ___ _______ _____________ 1 2 8 3 12 21 2 4 10 6 15 24 3 6 12 9 18 27

Convert table,T, to an array.

A = table2array(T)
A =1 2 8 3 12 21 2 4 10 6 15 24 3 6 12 9 18 27

Acontains two columns from variableTwoand three columns from variableThree.

Define the numeric subset of a table to convert to an array.

Create a table with nonnumeric data in the first variable.

T = table(categorical({'M';'M';'F';'F';'F'}),[38;43;38;40;49],...[71;69;64;67;64],[176;163;131;133;119],...'VariableNames',{'Gender''Age''Height''Weight'})
T =5×4 tableGender Age Height Weight ______ ___ ______ ______ M 38 71 176 M 43 69 163 F 38 64 131 F 40 67 133 F 49 64 119

ConvertT(:,2:4)to an array.

A = table2array(T(:,2:4))
A =38 71 176 43 69 163 38 64 131 40 67 133 49 64 119

Adoes not include data from the variableGender.

Create a table,T, with two rows and three variables where each variable has three dimensions.

T = table(ones(2,1,3),2*ones(2,2,3),3*ones(2,3,3),...'VariableNames',{'One''Two''Three'})
T =2×3 tableOne Two Three ______________ ______________ ______________ [1x1x3 double] [1x2x3 double] [1x3x3 double] [1x1x3 double] [1x2x3 double] [1x3x3 double]

The size of the table is 2-by-3.

Convert tableTto an array.

A = table2array(T)
A = (:,:,1) = 1 2 2 3 3 3 1 2 2 3 3 3 (:,:,2) = 1 2 2 3 3 3 1 2 2 3 3 3 (:,:,3) = 1 2 2 3 3 3 1 2 2 3 3 3

The size ofAis 2-by-6-by-3.

Input Arguments

collapse all

Input table, specified as a table. All variables inTmust have sizes and data types that are compatible for horizontal concatenation. Specifically, the size of all variable dimensions greater than2must match.

  • IfTis anm-byntable with variables that each have one column, then each variable becomes one column inA, andAis anm-by-narray.

  • IfTcontains variables that consist of more than one column, those variables become multiple columns inA, and the size ofAis greater than the size ofT.

  • IfTcontains variables with more than two dimensions, the number of dimensions ofAis the same as the number of variable dimensions.

Tips

  • table2arrayhorizontally concatenates the variables inT创建A. If the variables inTare cell arrays,table2arraydoes not concatenate their contents, andAis a cell array, equivalent totable2cell(T). To create an array containing the contents of variables that are all cell arrays, usecell2mat(table2cell(T)).

  • table2array(T)is equivalent toT{:,:}.

Algorithms

IfTcontains variables with different data types that are compatible for horizontal concatenation,table2arraycreates a homogeneous array,A, of the dominant data type. For example, ifTcontainsdoubleandsinglenumeric data,table2array(T)returns an array with data typesingle.

Extended Capabilities

Introduced in R2013b

这个主题有帮助吗?