| MATLAB Function Reference | ![]() |
Overloaded method for A(I), A{I} and A.field
Syntax
Description
B = subsref(A, S)
is called for the syntax A(i), A{i}, or A.i when A is an object. S is a structure array with the fields
type: A string containing '()', '{}', or '.', where '()' specifies integer subscripts, '{}' specifies cell array subscripts, and '.' specifies subscripted structure fields.
subs: A cell array or string containing the actual subscripts.
Remarks
subsref is designed to be used by the MATLAB interpreter to handle indexed references to objects. Calling subsref directly as a function is not recommended. If you do use subsref in this way, it conforms to the formal MATLAB dispatching rules and can yield unexpected results.
If A is an array of one of the fundamental MATLAB data types, then referencing a value of A using an indexed reference calls the builtin MATLAB subsref method. It does not call any subsref method that you may have overloaded for that data type. For example, if A is an array of type double, and there is an @double/subsref method on your MATLAB path, the statement B = A(I) does not call this method, but calls the MATLAB builtin subsref method instead.
Examples
The syntax A(1:2,:) calls subsref(A,S) where S is a 1-by-1 structure with S.type='()' and S.subs={1:2,':'}. A colon used as a subscript is passed as the string ':'.
The syntax A{1:2} calls subsref(A,S) where S.type='{}' and S.subs={1:2}.
The syntax A.field calls subsref(A,S) where S.type='.' and S.subs='field'.
These simple calls are combined in a straightforward way for more complicated subscripting expressions. In such cases length(S) is the number of subscripting 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:5} |
See Also
See Handling Subscripted Reference for more information about overloaded methods and subsref.
| subspace | substruct | ![]() |
© 1994-2005 The MathWorks, Inc.