MATLAB Object-Oriented Programming

(Joyce) #1

function output = myFunc(obj,arg1,arg2)
...
end


Static Methods in Separate Files


To create a static method, set the method Static attribute to true and list the function
signature in a static methods block in the classdef file. Include the input and output
arguments with the function name. For example:


classdef MyClass
...
methods (Static)
output = staticFunc1(arg1,arg2)
staticFunc2
end
...
end


Define the functions in separate files using the same function signature. For example, in
the file @MyClass/staticFunc1.m:


function output = staticFunc1(arg1,arg2)
...
end


and in @Myclass/staticFunc2.m:


function staticFunc2
...
end


Methods You Must Define in the classdef File


Define the following methods in the classdef file. You cannot define these methods in
separate files:



  • Class constructor

  • All functions that use dots in their names, including:

    • Converter methods that must use the package name as part of the class name
      because the class is contained in packages




Methods in Separate Files
Free download pdf