MATLAB Object-Oriented Programming

(Joyce) #1

Ordinary Methods


In this section...
“Ordinary Methods Operate on Objects” on page 9-8
“Methods Inside classdef Block” on page 9-8
“Method Files” on page 9-9

Ordinary Methods Operate on Objects


Ordinary methods define functions that operate on objects of the class. Therefore, one of
the input arguments must be an object or array of objects of the defining class. These
methods can compute values based on object data, can overload MATLAB built-in
functions, and can call other methods and functions. Ordinary methods can return
modified objects.

Methods Inside classdef Block


This example shows the definition of a method (methodName) within the classdef and
methods blocks:

classdef ClassName
methods (AttributeName = value,...)
function methodName(obj,args)
% method code
...
end
...
end % end of method block
...
end

Method attributes apply only to that particular methods block, which is terminated by the
end statement.

NoteNonstatic methods must include an explicit object variable as a function argument.
The MATLAB language does not support an implicit reference in the method function
definition.

9 Methods — Defining Class Operations

Free download pdf