MATLAB Object-Oriented Programming

(Joyce) #1

Call staticMethod using the syntax classname.methodname:


r = MyClass.staticMethod(arg1);


See “Static Methods” on page 9-32 for information on methods that do not require
objects of their class.


Private Methods


Use the Access method attribute to create a private method. You do not need to use a
private folder.


See “Method Attributes” on page 9-5 for a list of method attributes.


More Detailed Information On Methods


“Methods”


Class-Related Functions


You can define functions that are not class methods in the file that contains the class
definition (classdef). Define local functions outside of the classdef - end block, but
in the same file as the class definition. Functions defined in classdef files work like local
functions. You can call these functions from anywhere in the same file, but they are not
visible outside of the file in which you define them.


Local functions in classdef files are useful for utility functions that you use only within
that file. These functions can take or return arguments that are instances of the class but,
it is not necessary, as in the case of ordinary methods. For example, the following code
defines myUtilityFcn outside the classdef block:


classdef MyClass
properties
PropName
end
methods
function obj = MyClass(arg1)
obj.PropName = arg1;
end
end
end % End of classdef


Methods and Functions
Free download pdf