MATLAB Programming Fundamentals - MathWorks

(やまだぃちぅ) #1

Access Data in a Table


In this section...
“Ways to Index into a Table” on page 9-44
“Create Table from Subset of Larger Table” on page 9-46
“Create Array from the Contents of Table” on page 9-49

Ways to Index into a Table


A table is a container for storing column-oriented variables that have the same number of
rows. Parentheses allow you to select a subset of the data in a table and preserve the
table container. Curly braces and dot indexing allow you to extract data from a table.

If you use curly braces, the resulting array is the horizontal concatenation of the specified
table variables containing only the specified rows. The data types of all the specified
variables must be compatible for concatenation. You can then perform calculations using
MATLAB functions.

Dot indexing extracts data from one table variable. The result is an array of the same data
type as extracted variable. You can follow the dot indexing with parentheses to specify a
subset of rows to extract from a variable.

T.Variables horizontally concatenates all table variables into an array. T.Variables is
equivalent to T{:,:}.

To subscript into a table and select variables of a specified type, use the vartype
function.

Summary of Table Indexing Methods

Consider a table, T.

Type of
Indexing

Result Syntax Rows Variables

Parentheses table T(rows,var
s)

One or more rows,
specified by rows

One or more variables,
specified by vars
Curly Braces extracte
d data

T{rows,var
s}

One or more rows,
specified by rows

One or more variables,
specified by vars

9 Tables

Free download pdf