I have a dependent property that's somewhat expensive to calculate, so I don't want to re-calculate it unless I have to; i.e., unless the properties on which it depends change. Essentially, I want to do something like the snippet below, where the incrVal property would be expensive to calculate.
classdef MyClass < handle
properties val lazy = false end
properties (Dependent) incrVal end
properties (Access = private) savedIncrVal end
methods function obj = MyClass(val) obj.val = val; end
function set.val(obj, val) obj.val = val; obj.lazy = false; % I get a warning here. end
function incrVal = get.incrVal(obj) if obj.lazy incrVal = obj.savedIncrVal; else incrVal = obj.val + 1; % This is the expensive part. obj.savedIncrVal = incrVal; obj.lazy = true; end end