Suppose that you want to use object A to index into object B. B can be a single object or
an array, depending on the class designs.C = B(A);Here are two examples of subsindex methods. The first assumes you can convert class A
to a uint8. The second assumes class A stores an index value in a property.- The subsindex method implemented by class A can convert the object to numeric
format to be used as an index:
function ind = subsindex(obj)
ind = uint8(obj);
endThe class of obj implements a uint8 method to provide the conversion from the
object to an integer value.- Class A implements subsindex to return a numeric value that is stored in a property:
function ind = subsindex(obj)
ind = obj.ElementIndex;
endNotesubsindex values are 0-based, not 1-based.See Also
numArgumentsFromSubscript | subsasgn | subsrefRelated Examples
- “end as Object Index” on page 17-35
More About
- “Modify nargout and nargin for Indexing Methods” on page 17-9
17 Specialize Object Behavior