Redefine subscripted assignment
A = subsasgn(A,S,B)
A = subsasgn(A,S,B)
called by MATLAB^{®} for
the syntax A(i) = B
, A{i} = B
,
or A.i = B
when A
is an object.
MATLAB uses the builtin subsasgn
function
to interpret indexed assignment statements. Modify the indexed assignment
behavior of classes by overloading subsasgn
in
the class.
Note:
You must call 

Object used in indexing operation 

Structure with two fields,


Value being assigned (right side of assignment statement) 

Result of the assignment statement, which is the modified object passed in as the first argument. 
Argument values for the subsasgn
for the
expression shown:
A(1:2,:) = B;
The syntax A(1:2,:) = B
calls A
= subsasgn(A,S,B)
where S
is a structure
with S.type = '()'
and S.subs = {1:2,':'}
.
The colon character (':'
) indicates a colon used
as a subscript.
For the expression:
A{1:2} = B;
The syntax A{1:2} = B
calls A =
subsasgn(A,S,B)
where S.type = '{}'
and S.subs
= {[1 2]}
.
For the expression:
A.field = B;
The syntax A.field = B
calls A =
subsasgn(A,S,B)
where S.type = '.'
and S.subs
= 'field'
.
For the expression:
A(1,2).name(3:5) = B;
Simple calls combine in a straightforward way for more complicated
indexing expressions. In such cases, length(S)
is
the number of subscripting levels. For instance, A(1,2).name(3:5)
= B
calls A = subsasgn(A,S,B)
where S
is
a 3by1 array of structures with the following values:
S(1).type = '()'  S(2).type = '.'  S(3).type = '()' 
S(1).subs = {1,2}  S(2).subs = 'name'  S(3).subs = {[3 4 5]} 