I have an object that does a somewhat long calculation, stores the result, and then lets the user use it. If they change certain properties then it needs to be recalculated. So, in the set method for those properties, I just call the precalculation method. Ideally, if the user changed multiple properties at the same time – for example, set(obj,'A',a,'B',b) – then it wouldn't do the calculation twice. Is it possible for me to check how the set method was called? Ideally I could write something like:
classdef foo < matlab.mixin.SetGet properties (SetAccess=private) Expensive=[]; end properties a=1; b=2; end methods function DoSomethingHard(obj) Expensive=SomeLongCalculation(obj.a,obj.b); end function set.a(obj,value) obj.a=value; if NoMoreSetCallsComingUp obj.DoSomethingHard; end end function set.b(obj,value) obj.b=value; if NoMoreSetCallsComingUp obj.DoSomethingHard; end end end end
Except I don't know what "NoMoreSetCallsComingUp" would look like. Is this possible? Currently I'm just doing a lot of unnecessary computations…
Best Answer