主要内容

array2table

将同质阵列转换为表格

Description

example

T= array2table(A)转换m-经过-narray,A, to anm-经过-n桌子,T. Each column ofA成为变量T.

array2tableuses 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使用表格的名称'Var1',...,'VarN', whereN是列中的数量A.

example

T= array2table(A,Name,Value)creates a table from an array,A,有一个或多个指定的其他选项Name,Value配对参数。

For example, you can specify row names or variable names to include in the table.

Examples

collapse all

Create an array of numeric data.

A = [1 4 7; 2 5 8; 3 6 9]
A =3×31 4 7 2 5 8 3 6 9

转换数组,A,到桌子上。

T = array2table(A)
T=3×3桌子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.

Create an array of numeric data.

a = [1 12 30.48;2 24 60.96;3 36 91.44]
A =3×31.0000 12.0000 30.4800 2.0000 24.0000 60.9600 3.0000 36.0000 91.4400

转换数组,A, to a table and include variable names.

T = array2table(A,...'VariableNames',{'Feet','Inches','Centimeters'})
T=3×3桌子Feet Inches Centimeters ____ ______ ___________ 1 12 30.48 2 24 60.96 3 36 91.44

Input Arguments

collapse all

输入数组,指定为矩阵。

Data Types:single|double|int8|INT16|INT32|int64|uint8|UINT16|uint32|uint64|logical|char|string|struct|细胞
Complex Number Support:Yes

Name-Value Arguments

将可选的参数对Name1=Value1,...,NameN=ValueN, whereNameis the argument name and价值是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

例子:'RowNames',{'row1','row2','row3'}uses the row names,行1,Row2, 和Row3for the table,T.

Row names forT, specified as the comma-separated pair consisting of'RowNames'和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®字符,包括空格和非ASCII字符。

If you specify row names that have leading or trailing whitespace characters, thenarray2tableremoves them from the row names.

Variable names forT, specified as the comma-separated pair consisting of'VariableNames'以及字符矢量或字符串阵列的单元格数组,其元素是非空的且独特的。名称的数量必须等于变量的数量,size(A,2).

Variable names can have any Unicode characters, including spaces and non-ASCII characters.

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.

在R2021a之前,您只能通过设置DimensionNames输出的属性。

Output Arguments

collapse all

输出表,返回为表。该表可以存储元数据,例如描述,可变单元,可变名称和行名称。有关更多信息,请参见“属性”部分桌子.

提示

  • IfAis a cell array, useCell2table(a)to create a table from the contents of the cells inA. Each variable in the table is numeric or a cell array of character vectors.array2table(A)创建一个表,每个变量是单元列。

Extended Capabilities

Version History

在R2013B中引入

expand all

Behavior changed in R2019b