subsasgn
(Not Recommended) Subscripted assignment to dataset array
The dataset
data type is not recommended. To work with heterogeneous data,
use the MATLAB®
table
data type instead. See MATLAB
table
documentation for more information.
Description
A = subsasgn(A,S,B)
is called for the syntax
A(i,j)=B
, A{i,j}=B
, or A
.
var=B
when A
is a dataset array.
S
is a structure array with the fields:
type | '()' , '{}' , or
'.' specifying the subscript type. |
subs | Cell array or character vector containing the actual subscripts. |
A(i,j) = B
assigns the contents of the dataset array
B
to a subset of the observations and variables in the dataset
array A
. i
and j
are one of the
following types:
positive integers
vectors of positive integers
observation/variable names
cell arrays containing one or more observation/variable names
logical vectors
The assignment does not use observation names, variable names, or any
other properties of B
to modify properties of A
;
however properties of A
are extended with default values if the
assignment expands the number of observations or variables in A
.
Elements of B
are assigned into A
by position, not
by matching names.
A{i,j} = B
assigns the value B
into an element
of the dataset array A
. i
and J
are positive integers, or logical vectors. Cell indexing cannot assign into multiple
dataset elements, that is, the subscripts i
and j
must each refer to only a single observation or variable. B
is cast
to the type of the target variable if necessary. If the dataset element already exists,
A{i,j}
may also be followed by further subscripting as supported
by the variable.
For dataset variables that are cell arrays, assignments such as
A{1,'CellVar'} = B
assign into the contents of the target dataset
element in the same way that {}
-indexing of an ordinary cell array
does.
For dataset variables that are n
-D arrays, i.e., each observation
is a matrix or array, an assignment such as A{1,'ArrayVar'} = B
assigns into the second and following dimensions of the target dataset element, i.e.,
the assignment adds a leading singleton dimension to B
to account for
the observation dimension of the dataset variable.
A.var = B
or A.(varname) = B
assigns
B
to a dataset variable. var
is a variable
name literal, or varname
is a character variable containing a
variable name. If the dataset variable already exists, the assignment completely
replaces that variable. To assign into an element of the variable,
A.var
or A.(varname)
may be followed by
further subscripting as supported by the variable. In particular,
A.var(obsnames,...) = B
and A.var{obsnames,...} =
B
(when supported by var
) provide assignment into a
dataset variable using observation names.
A.properties.propertyname = P
assigns to a dataset property.
propertyname
is one of the following:
'ObsNames'
'VarNames'
'Description'
'Units'
'DimNames'
'UserData'
'VarDescription'
To assign into an element of the property,
A.properties.propertyname
may also be followed by further
subscripting as supported by the property.
You cannot assign multiple values into dataset variables or properties using
assignments such as [A.CellVar{1:2}] = B
,
[A.StructVar(1:2).field] = B
, or
[A.Properties.ObsNames{1:2}] = B
. Use multiple assignments of the
form A.CellVar{1} = B
instead.
Similarly, if a dataset variable is a cell array with multiple columns or is an
n
-D cell array, then the contents of that variable for a single
observation consists of multiple cells, and you cannot assign to all of them using the
syntax A{1,'CellVar'} = B
. Use multiple assignments of the form
[A.CellVar{1,1}] = B
instead.