Access Data in Tables
In this section...
“Summary of Table Indexing Syntaxes” on page 9-32
“Tables Containing Specified Rows and Variables” on page 9-35
“Extract Data Using Dot Notation and Logical Values” on page 9-38
“Dot Notation with Any Variable Name or Expression” on page 9-40
“Extract Data from Specified Rows and Variables” on page 9-42
A table is a container that stores column-oriented data in variables. Table variables can have different
data types and sizes as long as all variables have the same number of rows. Table variables have
names, just as the fields of a structure have names. The rows of a table can have names, but row
names are not required. To access table data, index into the rows and variables using either their
names or numeric indices.
Typical reasons for indexing into tables include:
• Reordering or removing rows and variables.
• Adding arrays as new rows or variables.
• Extracting arrays of data to use as input arguments to functions.
Summary of Table Indexing Syntaxes
Depending on the type of indexing you use, you can access either a subtable or an array extracted
from the table. Indexing with:
• Smooth parentheses, (), returns a table that has selected rows and variables.
• Dot notation returns the contents of a variable as an array.
• Curly braces, {}, returns an array concatenated from the contents of selected rows and
variables.
You can specify rows and variables by name, numeric index, or data type. Starting in R2019b,
variable names and row names can include any characters, including spaces and non-ASCII
characters. Also, they can start with any characters, not just letters. Variable and row names do not
have to be valid MATLAB identifiers (as determined by the isvarname function).
9 Tables
9-32
In this section...
“Summary of Table Indexing Syntaxes” on page 9-32
“Tables Containing Specified Rows and Variables” on page 9-35
“Extract Data Using Dot Notation and Logical Values” on page 9-38
“Dot Notation with Any Variable Name or Expression” on page 9-40
“Extract Data from Specified Rows and Variables” on page 9-42
A table is a container that stores column-oriented data in variables. Table variables can have different
data types and sizes as long as all variables have the same number of rows. Table variables have
names, just as the fields of a structure have names. The rows of a table can have names, but row
names are not required. To access table data, index into the rows and variables using either their
names or numeric indices.
Typical reasons for indexing into tables include:
• Reordering or removing rows and variables.
• Adding arrays as new rows or variables.
• Extracting arrays of data to use as input arguments to functions.
Summary of Table Indexing Syntaxes
Depending on the type of indexing you use, you can access either a subtable or an array extracted
from the table. Indexing with:
• Smooth parentheses, (), returns a table that has selected rows and variables.
• Dot notation returns the contents of a variable as an array.
• Curly braces, {}, returns an array concatenated from the contents of selected rows and
variables.
You can specify rows and variables by name, numeric index, or data type. Starting in R2019b,
variable names and row names can include any characters, including spaces and non-ASCII
characters. Also, they can start with any characters, not just letters. Variable and row names do not
have to be valid MATLAB identifiers (as determined by the isvarname function).
9 Tables
9-32
