Class attribute
classdef block
classdef keyword begins definition block.
end keyword terminates definition block.
classdef (ConstructOnLoad = true) PositiveIntegers < Integers & Positives
...
end
Attribute value
(logical true)
Class name Super classes
Class Code
Here is a simple class definition with one property and a constructor method that sets the
value of the property when there is an input argument supplied.
classdef MyClass
properties
Prop
end
methods
function obj = MyClass(val)
if nargin > 0
obj.Prop = val;
end
end
end
end
To create an object of MyClass, save the class definition in a .m file having the same
name as the class and call the constructor with any necessary arguments:
d = datestr(now);
o = MyClass(d);
6 Defining and Organizing Classes