plato/objects.m

32 lines
648 B
Matlab

% instantiate an object of type BasicClass (see BasicClass.m)
obj = BasicClass;
assert(isempty(obj.Value));
obj.Value = 3;
obj.Value = [3 4.5];
% methods can be called in two ways
roundOff(obj);
% or dot notation
obj.roundOff();
% use the constructor
v = BasicClass(42);
assert(v.Value == 42);
% object arrays are presto supported
objs(1) = BasicClass(44);
objs(2) = BasicClass(33);
% [objs.Value] expands to [objs(1).Value ...]
assert(isequal( [objs.Value], [44 33] ));
% you can also do this with a cell array
assert(isequal( {objs.Value}, {44, 33} ));
% operator overloading
obj + objs(1);
% also works for object arrays
[objs] + [objs]