Indexed Assignment
In this section...
“How Indexed Assignment Works” on page 17-31
“Indexed Assignment to Objects” on page 17-33
“Compound Indexed Assignments” on page 17-33
How Indexed Assignment Works
Object indexed assignments are in three forms — parentheses, braces, and dot-name:
A(I) = B
A{I} = B
A.name = B
Each of these statements results in a call by MATLAB to the subsasgn method of class A,
or a call to the built-in subsasgn function if the class of A does not implement a
subsasgn method.
MATLAB passes three arguments to subsasgn and requires subsasgn to return the
result of the assignment:
A = subsasgn(A,S,B)
The first argument, A, is the object being assigned the value in the third argument B.
The second argument is the indexing structure, substruct. S has two fields:
- S.type is a char vector containing '()', '{}', or '.' specifying the indexing type
used. - S.subs is a cell array or character array containing the actual indices or field name. A
colon used as an index is passed in the cell array as the character ':'. Ranges
specified using a colon (e.g., 2:5) are expanded to 2 3 4 5.
For example, the assignment statement:
A(2,3) = B;
generates a call to subsasgn:
A = subsasgn(A,S,B)
Indexed Assignment