Customize Object Indexing
Customize indexed reference and assignment behavior for objects. User-defined classes possess the same indexing behavior as built-in MATLAB® classes, but you can modify this behavior by inheriting from one or more superclasses.
Modular indexing mixin classes enable you to customize
indexing operations individually. For example, you can customize parentheses
indexing by inheriting from
matlab.mixin.indexing.RedefinesParen
, while using the
default MATLAB behavior for dot and brace indexing without writing additional
code.
You can also overload the subsref
and
subsasgn
functions in your classes, but this
technique requires you to overload parentheses, dot, and brace indexing,
even if you need to customize only one behavior. Using the modular indexing
classes is the recommended procedure whenever possible.
Classes
matlab.mixin.indexing.RedefinesParen | Customize class indexing operations that use parentheses (Since R2021b) |
matlab.mixin.indexing.RedefinesDot | Customize class indexing operations that use dots (Since R2021b) |
matlab.mixin.indexing.RedefinesBrace | Customize class indexing operations that use braces (Since R2021b) |
matlab.indexing.IndexingOperation | Type of customized indexing operation and referenced indices (Since R2021b) |
matlab.mixin.Scalar | Enforce scalar behavior for class instances (Since R2021b) |
matlab.mixin.indexing.ForbidsPublicDotMethodCall | Disallow calling public methods using dot notation (Since R2021b) |
matlab.mixin.indexing.OverridesPublicDotMethodCall | Calling public methods with dot notation invokes overloaded dot indexing (Since R2021b) |
Functions
builtin | Execute built-in function from overloaded method |
numArgumentsFromSubscript | Number of arguments for customized indexing based on subsref and subsasgn |
matlab.indexing.isScalarClass | Determine whether input is scalar class (Since R2024b) |
listLength | Number of arguments returned from customized indexing operations (Since R2021b) |
subsref | Subscripted reference |
subsasgn | Redefine subscripted assignment |
subsindex | Convert object to array index |
substruct | Create structure argument for subsasgn or subsref |
Topics
- Customize Object Indexing
MATLAB classes support object array indexing by default.
- Customize Parentheses Indexing for Mapping Class
This example shows how to customize parentheses indexing for a mapping class.
- Forward Indexing Operations
Forward additional levels of indexing after customized indexing operations.
- Overload end for Classes
Overload
end
for customized indexing applications. - Objects in Index Expressions
You can design objects that can be used as indices in indexing expressions.
- Code Patterns for subsref and subsasgn Methods
There are code patterns useful for modifying object indexing.