Redefine subscripted reference for objects
B = subsref(A,S)
B = subsref(A,S)
is called by MATLAB® for
the syntax A(i)
, A{i}
, or A.i
when A
is
an object.
MATLAB uses the built-in subsref
function
to interpret indexed references to objects. To modify the indexed
reference behavior of objects, overload subsref
in
the class.
|
Object used in indexing operation |
|
Structure with two fields,
|
|
Result of the indexed expression. If your implementation of a |
See how MATLAB calls subsref
for the
expression:
A(1:2,:)
The syntax A(1:2,:)
calls B = subsref(A,S)
where S
is
a 1-by-1 structure with S.type='()'
and S.subs={1:2,':'}
.
The colon character ':'
indicates a colon used
as a subscript.
See how MATLAB calls subsref
for the
expression:
A{1:2}
The syntax A{1:2}
calls B = subsref(A,S)
where S.type='{}'
and S.subs={[1
2]}
.
See how MATLAB calls subsref
for the
expression:
A.field
The syntax A.field
calls B = subsref(A,S)
where S.type='.'
and S.subs='field'
.
See how MATLAB calls subsref
for the
expression:
A(1,2).name(3:5)
Simple calls combine in a straightforward way for more complicated
indexing expressions. In such cases, length(S)
is
the number of subscript levels. For instance, A(1,2).name(3:5)
calls subsref(A,S)
where S
is
a 3-by-1 structure array 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]} |