"where all properties are non-dependent" Why? Your properties are obviously dependent, so why not use them.
The warnings are telling you that if an object is saved in a mat file it may not be restored properly due to random initialisation order. In practice, with your design, that shouldn't be a problem as the properties' values should always be consistent, so I guess you could just disable the warnings.
However, I can't help but greatly dislike this design, particularly the i state variable. You could achieve a cleaner design, using dependent variables, with no impact on performance:
classdef AeqKxB
properties(Dependent)
A;
B;
K;
end
properties
Kstate;
end
properties (Access = private)
A_;
B_;
K_;
end
methods
function obj = AeqKxB(a, k, kstate)
obj.A_ = a;
obj.B_ = a*k;
obj.K_ = k;
obj.Kstate = kstate;
end
function a = get.A(obj)
a = obj.A_;
end
function obj = set.A(obj, a)
obj.A_ = a;
obj.B_ = a / obj.K_;
end
function b = get.B(obj)
b = obj.B_;
end
function obj = set.B(obj, b)
obj.B_ = b;
obj.A_ = b * obj.K_;
end
function obj = set.K(obj,k)
obj.K_ = k;
if strcmp(obj.Kstate, 'FixB')
obj.A_ = obj.B_ * k;
elseif strcmp(obj.Kstate, 'FixA')
obj.B_ = obj.A_ / k;
end
end
function obj = set.Kstate(obj,kstate)
obj.Kstate = kstate;
end
end
end
Best Answer