Documentation

Object Indexing

Customize subscripted reference and assignment for your class.

Customize indexed reference and assignment behavior for object arrays. Although user-defined classes possess the same indexing behavior as built-in MATLAB®classes, you can modify this behavior when your class has special requirements.

Functions

numArgumentsFromSubscript Number of arguments for customized indexing methods
subsref Subscripted reference
subsasgn Redefine subscripted assignment
subsindex Convert object to array index
substruct Create structure argument for subsasgn or subsref
builtin Execute built-in function from overloaded method

Topics

How Indexing Works

Object Array Indexing

MATLAB classes support object array indexing by default.

Indexed Reference

Learn about subscripted reference.

Indexed Assignment

Learn about subscripted assignment.

Customize Indexing

Code Patterns for subsref and subsasgn Methods

There are code patterns useful for modifying object indexing.

Number of Arguments for subsref and subsasgn

Classes that modify object array indexing must handle the correct number of arguments retrurned from or passed to indexing methods.

Modify nargout and nargin for Indexing Methods

Modify the number of arguments passed to or returned from indexing methods.

Special Indices

end as Object Index

Learn how to implement the use ofendfor object indexing.

Objects in Index Expressions

You can design objects that can be used as indices in indexing expressions.

Class with Modified Indexing

This sample class implementation modifies object indexing.