Main Content

Customize Object Indexing

Customize indexed reference and assignment for your class

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.RedefinesParenCustomize class indexing operations that use parentheses (Since R2021b)
matlab.mixin.indexing.RedefinesDotCustomize class indexing operations that use dots (Since R2021b)
matlab.mixin.indexing.RedefinesBraceCustomize class indexing operations that use braces (Since R2021b)
matlab.indexing.IndexingOperationType of customized indexing operation and referenced indices (Since R2021b)
matlab.mixin.ScalarEnforce scalar behavior for class instances (Since R2021b)
matlab.mixin.indexing.ForbidsPublicDotMethodCallDisallow calling public methods using dot notation (Since R2021b)
matlab.mixin.indexing.OverridesPublicDotMethodCallCalling public methods with dot notation invokes overloaded dot indexing (Since R2021b)

Functions

builtinExecute built-in function from overloaded method
numArgumentsFromSubscriptNumber of arguments from indexing methods
matlab.indexing.isScalarClassDetermine whether input is scalar class (Since R2024b)
listLengthNumber of arguments returned from customized indexing operations (Since R2021b)
subsrefIndexed reference using function call
subsasgnSubscripted assignment using function call
subsindexConvert object to array index
substructCreate indexing structure argument

Topics