MATLAB Object-Oriented Programming

(Joyce) #1
...
end
end

How MATLAB Interprets the Function Call


The special support for array-creation functions results from the interpretation of the
syntax.



  • A call to the zeros function of this form:


zeros(...,'ClassName')

Calls the class static method with this syntax:

ClassName.zeros(varargin{1:end-1})


  • A call to the zeros function of this form:


zeros(...,'like',obj)

Calls the class method with this syntax:

zerosLike(obj,varargin{1:end-2})

Support All Function Inputs


The input arguments to an array-creation function can include the dimensions of the
array the function returns and possibly other arguments. In general, there are three cases
that your methods must support:



  • No dimension input arguments resulting in the return of a scalar. For example:


z = zeros('MyClass');


  • One or more dimensions equal to or less than zero, resulting in an empty array. For
    example:


z = zeros(2,0,'MyClass');


  • Any number of valid array dimensions specifying the size of the array. For example:


z = zeros(2,3,5,'MyClass');

When the array-creation function calls your class method, it passes the input arguments,
excluding the class name or the literal 'like' and the object variable to your method.
You can implement your methods with these signatures:


Class Support for Array-Creation Functions
Free download pdf