Convert hom*ogeneous array to table (2024)

Convert hom*ogeneous array to table

collapse all in page

Syntax

T = array2table(A)

T = array2table(A,Name,Value)

Description

example

T = array2table(A) convertsthe m-by-n array, A,to an m-by-n table, T.Each column of A becomes a variable in T.

array2table uses 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 uses names of the form 'Var1',...,'VarN', where N is the number of columns in A.

example

T = array2table(A,Name,Value) createsa table from an array, A, with additional optionsspecified by one or more Name,Value pair arguments.

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

Examples

collapse all

Convert Numeric Array to Table

Open Live Script

Create an array of numeric data.

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

Convert the array, A, to a table.

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

Convert Array to Table Including Variable Names

Open Live Script

Create an array of numeric data.

A = [1 12 30.48; 2 24 60.96; 3 36 91.44]
A = 3×3 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 table Feet Inches Centimeters ____ ______ ___________ 1 12 30.48 2 24 60.96 3 36 91.44 

Input Arguments

collapse all

AInput array
matrix

Input array, specified as a matrix.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64 | logical | char | string | struct | cell
Complex Number Support: Yes

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'RowNames',{'row1','row2','row3'} uses the row names, row1, row2, and row3 for the table, T.

RowNamesRow names for T
{} (default) | cell array of character vectors | string array

Row names for T, specified as the comma-separated pair consisting of 'RowNames' and 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® characters, including spaces and non-ASCII characters.

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

VariableNamesVariable names for T
cell array of character vectors | string array

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

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

DimensionNamesDimension names
two-element cell array of character vectors | two-element string array

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.

Before R2021a, you can specify dimension names only by setting the DimensionNames property of the output.

Output Arguments

collapse all

Tips

  • If A is a cell array, use cell2table(A) tocreate a table from the contents of the cells in A.Each variable in the table is numeric or a cell array of charactervectors. array2table(A) creates a table where eachvariable is a column of cells.

Extended Capabilities

Thread-Based Environment
Run code in the background using MATLAB® backgroundPool or accelerate code with Parallel Computing Toolbox™ ThreadPool.

Version History

Introduced in R2013b

expand all

See Also

table2array | cell2table | struct2table | table | isvarname

Topics

  • Access Data in Tables

MATLAB Command

You clicked a link that corresponds to this MATLAB command:

 

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Convert hom*ogeneous array to table (1)

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

Americas

  • América Latina (Español)
  • Canada (English)
  • United States (English)

Europe

  • Belgium (English)
  • Denmark (English)
  • Deutschland (Deutsch)
  • España (Español)
  • Finland (English)
  • France (Français)
  • Ireland (English)
  • Italia (Italiano)
  • Luxembourg (English)
  • Netherlands (English)
  • Norway (English)
  • Österreich (Deutsch)
  • Portugal (English)
  • Sweden (English)
  • Switzerland
    • Deutsch
    • English
    • Français
  • United Kingdom (English)

Asia Pacific

  • Australia (English)
  • India (English)
  • New Zealand (English)
  • 中国
  • 日本 (日本語)
  • 한국 (한국어)

Contact your local office

Convert hom*ogeneous array to table (2024)
Top Articles
Latest Posts
Article information

Author: Sen. Ignacio Ratke

Last Updated:

Views: 5890

Rating: 4.6 / 5 (76 voted)

Reviews: 83% of readers found this page helpful

Author information

Name: Sen. Ignacio Ratke

Birthday: 1999-05-27

Address: Apt. 171 8116 Bailey Via, Roberthaven, GA 58289

Phone: +2585395768220

Job: Lead Liaison

Hobby: Lockpicking, LARPing, Lego building, Lapidary, Macrame, Book restoration, Bodybuilding

Introduction: My name is Sen. Ignacio Ratke, I am a adventurous, zealous, outstanding, agreeable, precious, excited, gifted person who loves writing and wants to share my knowledge and understanding with you.