Products & Services Solutions Academia Support User Community Company

Learn more about Statistics Toolbox   

subsref - Class: dataset

Subscripted reference for dataset array

Syntax

B = subsref(A,S)

Description

B = subsref(A,S) is called for the syntax A(i,j), A{i,j}, or A.var when A is a dataset array. S is a structure array with the fields:

typeString containing '()', '{}', or '.' specifying the subscript type.
subsCell array or string containing the actual subscripts.

B = A(i,j) returns a dataset array that contains a subset of the observations and variables in the dataset array A. i and j are one of the following types:

B contains the same property values as A, subsetted for observations or variables where appropriate.

B = A{i,j} returns an element of a dataset variable. i and j are positive integers, or logical vectors. Cell indexing cannot return multiple dataset elements, that is, the subscripts i and j must each refer to only a single observation or variable. A{i,j} may also be followed by further subscripting as supported by the variable.

For dataset variables that are cell arrays, expressions such as A{1,'CellVar'} return the contents of the referenced dataset element in the same way that {}-indexing on an ordinary cell array does. If the dataset variable is a single column of cells, the contents of a single cell is returned. If the dataset variable has multiple columns or is n-D, multiple outputs containing the contents of multiple cells are returned.

For dataset variables that are n-D arrays, i.e., each observation is a matrix or an array, expressions such as A{1,'ArrayVar'} return A.ArrayVar(1,:,...) with the leading singleton dimension squeezed out.

B = A.var or A.(varname) returns a dataset variable. var is a variable name literal, or varname is a character variable containing a variable name. A.var or A.(varname) may also be followed by further subscripting as supported by the variable. In particular, A.var(obsnames,...) and A.var{obsnames,...} (when supported by var) provide subscripting into a dataset variable using observation names.

P = A.Properties.propertyname returns a dataset property. propertyname is one of the following:

A.properties.propertyname may also be followed by further subscripting as supported by the property.

Limitations

Subscripting expressions such as A.CellVar{1:2}, A.StructVar(1:2).field, or A.Properties.ObsNames{1:2} are valid, but result in subsref returning multiple outputs in the form of a comma-separated list. If you explicitly assign to output arguments on the left-hand side of an assignment, for example, [cellval1,cellval2] = A.CellVar{1:2}, those variables will receive the corresponding values. However, if there are no output arguments, only the first output in the comma-separated list is returned.

Similarly, if a dataset variable is a cell array with multiple columns or is an n-D cell array, then subscripting expressions such as A{1,'CellVar'} result in subsref returning the contents of multiple cells. You should explicitly assign to output arguments on the left-hand side of an assignment, for example, [cellval1,cellval2] = A{1,'CellVar'}.

See Also

dataset, set, subsasgn

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS