subsindex
Method a class overloads so that its objects can be used as array indices.
Category: Programming > Classes
Syntax
ind = subsindex(obj)
Returns the zero-based index that obj stands for when it appears inside parentheses.
Description
When an object appears as an index, as in v(obj), MATLAB calls the class's subsindex method and adds one to the result. The method returns zero-based values, which is a historical convention, so a class that wraps a one-based position must subtract one.
Ordinary numeric, logical and char arrays have no subsindex; calling it on one is an error that names the class of the argument.
Input arguments
obj- An object of a class that defines
subsindex.
Output arguments
ind- Numeric array of zero-based indices, so the value
0selects the first element.
Example
The method does not exist for plain numbers
try
subsindex(5)
catch err
disp(err.message)
end
Function 'subsindex' is not defined for values of class 'double'.
Notes
MatLivre does not support objects as indices: v(obj) reports that indexing with that class is not supported, even if the class defines subsindex. The wording of the error in the example may differ from MATLAB's.