MATLAB Object-Oriented Programming

(Joyce) #1

p = MyClass(...);
zArray = zeros(size(p),'like',p);


MATLAB uses these arguments to dispatch to the appropriate method in your class.


Array-Creation Functions That Support Overloading


The following functions support this kind of overloading.


Array-Creation Functions
ones
zeros
eye
nan (lowercase)
inf
true
false
cast
rand
randn
randi

Which Syntax to Use


To create an array of default objects, which require no input arguments for the
constructor, then use the class name syntax.


To create an array of objects with specific property values or if the constructor needs
other inputs, use the prototype object to provide this information.


Classes can support both the class name and the prototype object syntax.


You can implement a class name syntax with the true and false functions even though
these functions do not support that syntax by default.


Class Support for Array-Creation Functions
Free download pdf