Looking for way to trigger method from outside the class or property condition

3 views (last 30 days)
I have a class structure that looks like...
classdef Main < handle
properties
ObjArray % cell array 1..n with instances of 'System'
end
methods
% Constructor: object array all of the same class 'System' passed in
function obj = Main(ObjArraySystems)
obj.ObjArray = ObjArraySystems;
end
% for updating state: some (in this case) some random value passed to each object by a loop
function update(obj)
for system_id = 1:length(obj.ObjArray)
value = randi(100);
obj.ObjArray{system_id}.setState(system_id,value);
end
end
end
end
% System class
classdef System < handle
properties (Constant)
State = SystemState
end
methods
function setState(obj,system_id,value)
obj.State.lokalStates(system_id) = value;
end
end
end
% SystemState
classdef SystemState < handle
properties
lokalStates % array holds state for each system, length is number of systems
end
methods
function calculationOnArray(obj)
% performs some calculation on lokalStates array, simple e.g,
obj.lokalStates = arrayfun(@(x) mean(obj.lokalStates),obj.lokalStates);
end
end
end
The desired behavior of the updating process should be as follows: Main passes a new value to each system, these in turn saves the value into a common array (Static Data Object). As soon as the array is 'filled' (last value is passed in), the function ->calculationOnArray should start.
Now, I struggle to find a good solution to trigger the calculation...
1) After the updating loop
obj.ObjArray{1,1}.State.calculationOnArray()
2) calculationOnArray as static method
SystemState.calculationOnArray(obj.ObjArray{1,1}.State)
3) Some other setmethod inside SystemState
function setState(obj,sytem_id,value) %<- called from 'System'
obj.lokalStates(system_id) = value;
if system_id == obj.NumberofSystems % new property set in constructor of 'SystemState'
obj.calculationOnArray()
end
end
4) Best would be if it triggers independently somehow, or the function has a dirct handle to the Main calss...
THX

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!