MATLAB Object-Oriented Programming

(Joyce) #1
numArgumentsFromSubscript function to control nargout for subsref and nargin
for subsasgn. For more information and examples, see numArgumentsFromSubscript.

Indexing Structure Describes Indexing Expressions


The indexing structure contains information that describes the indexing expression. Class
methods use the information in the indexing structure to evaluate the expression and
implement custom behavior.

For example, the CustomIndex class defines a property that you can use in indexing
expressions.

classdef CustomIndex
properties
DataArray
end
end

Create an object and assign a 5-by-5 matrix created by the magic function to the
DataArray property.

a = CustomIndex;
a.DataArray = magic(5);

This subscripted reference expression returns the first row of the 5-by-5 matrix.

a.DataArray(1,:)

ans =

17 24 1 8 15

This expression assigns new values to the first row of the array stored in the DataArray
property.

a.DataArray(1,:) = [1 2 3 4 5];

This assignment statement uses:


  • A '.' type reference

  • A property name following the dot (that is, DataArray)

  • A range of indices (1,:) within parentheses


17 Specialize Object Behavior

Free download pdf