Documentation

array2table

将同质阵列转换为表格

Syntax

T = array2table(A)
T = array2table(A,Name,Value)

Description

example

T= array2table(A)转换m-by-narray,A, to anm-by-ntable,T. Each column ofAbecomes a variable inT.

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,array2tableuses character vectors of the form'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 =1 4 7 2 5 8 3 6 9

Convert the array,A, to a table.

T = array2table(A)
T =3×3 tableA1 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 =1.0000 12.0000 30.4800 2.0000 24.0000 60.9600 3.0000 36.0000 91.4400

Convert the array,A, to a table and include variable names.

T = array2table(A,...'VariableNames',{'Feet','Inches','Centimeters'})
T =3×3 tableFeet 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|struct|cell
Complex Number Support:Yes

Name-Value Pair Arguments

Specify optional comma-separated pairs ofName,Valuearguments.Nameis the argument name and价值是相应的值。Name必须出现在单引号中(' '). You can specify several name and value pair arguments in any order asNAME1,Value1,...,Namen,Valuen.

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

collapse all

Row names forT, specified as the comma-separated pair consisting of'RowNames'and a cell array of character vectors that are nonempty and distinct. The number of character vectors must equal the number of rows,size(A,1).

Variable names forT, specified as the comma-separated pair consisting of'VariableNames'and a cell array of character vectors that are nonempty and distinct. The number of character vectors must equal the number of variables,size(A,2).

此外,变量名MATL必须是合法的AB identifiers. If valid MATLAB identifiers are not available for use as variable names, MATLAB uses a cell array ofNcharacter vectors of the form{'Var1' ... 'VarN'}whereNis the number of variables. You can determine valid MATLAB variable names using the functionISVARNAME.

Output Arguments

collapse all

输出表,返回为表。该表可以存储元数据,例如描述,可变单元,可变名称和行名称。有关更多信息,请参阅Table Properties.

Tips

  • 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

在R2013B中引入

这个话题有帮助吗?