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 (since R2021b) 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
You can also overload the
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.
|Customize class indexing operations that use parentheses|
|Customize class indexing operations that use dots|
|Customize class indexing operations that use braces|
|Type of customized indexing operation and referenced indices|
|Enforce scalar behavior for class instances|
|Disallow calling public methods using dot notation|
|Calling public methods with dot notation invokes overloaded dot indexing|
|Redefine subscripted assignment|
|Convert object to array index|
|Create structure argument for |
|Execute built-in function from overloaded method|
|Number of arguments for customized indexing based on subsref and subsasgn|
MATLAB classes support object array indexing by default.
This example shows how to customize parentheses indexing for a mapping class.
Forward additional levels of indexing after customized indexing operations.
Learn how to implement the use of
end for object indexing.
You can design objects that can be used as indices in indexing expressions.
There are code patterns useful for modifying object indexing.