Main Content


Number of arguments returned from customized indexing operations

Since R2021b



n = listLength(obj,indexOp,indexContext) returns the number of outputs n expected from a customized indexing operation performed on obj. The indexOp object describes the types of indexing operations and indices referenced, and the indexContext instance identifies whether the indexing operation occurs in a statement, expression, or assignment.


collapse all

In the example shown in matlab.mixin.indexing.RedefinesDot, the ScalarStructClass inherits from RedefinesDot to implement custom dot indexing. The AddedFields property of ScalarStructClass is a struct, and in cases where an indexing operation returns or assigns to a comma-separated list, the class calls the dotListLength method.

In turn, dotListLength turn calls listLength on the AddedFields property.

methods (Access=protected)
  function n = dotListLength(obj,indexOp,indexContext)
    n = listLength(obj.AddedFields,indexOp,indexContext);

For the full implementation of ScalarStructClass, see Customize Dot Indexing in a Scalar Class.

Input Arguments

collapse all

Object being indexed into.

Type of indexing operation and indices referenced, specified as an array of IndexingOperation objects.

Context in which the indexing operation occurs, specified as one of these enumeration members:

  • matlab.indexing.IndexingContext.Statement — Indexed reference used as a statement (for example, obj.a)

  • matlab.indexing.IndexingContext.Expression — Indexed reference used as an argument to a function (for example, func(obj.a))

  • matlab.indexing.IndexingContext.Assignment — Indexed assignment (for example, [obj.a] = deal(x)).

Output Arguments

collapse all

Number of values to return from an indexing operation, specified as a nonnegative integer.

Version History

Introduced in R2021b