MATLAB Object-Oriented Programming

(Joyce) #1
function n = numArgumentsFromSubscript(obj,s,indexingContext)
...
end

Input Argument Description
obj Object whose subsref or subsasgn method is called
s Indexing structure that contains the indexing type and indices used
in the operation
indexingContex
t

Context in which the indexing operation occurs: indexed reference
used as a statement, index reference used as a function argument,
and indexed assignment

MATLAB uses the value returned by numArgumentsFromSubscript for indexed
reference and assignment. Determine the context in which the indexing operation
executes by testing the value of indexingContext in your implementation of
numArgumentsFromSubscript. For example, test for any or all the possible indexing
contexts.
function n = numArgumentsFromSubscript(obj,~,indexingContext)
switch indexingContext
case matlab.mixin.util.IndexingContext.Statement
n = ...; % nargout for indexed reference used as statement
case matlab.mixin.util.IndexingContext.Expression
n = ...; % nargout for indexed reference used as function argument
case matlab.mixin.util.IndexingContext.Assignment
n = ...; % nargin for indexed assignment
end
end

For more information and examples, see numArgumentsFromSubscript.

NoteFor MATLAB version R2015b and later releases, overload
numArgumentsFromSubscript instead of numel to customize indexing for your class.

See Also


More About



  • “Number of Arguments for subsref and subsasgn” on page 17-6

  • “Use of size and numel with Classes” on page 12-77


17 Specialize Object Behavior

Free download pdf