Using a private method to set a number of private properties
12 views (last 30 days)
Show older comments
I'm trying to work with OOP concepts in MATLAB but run into the following problem: I have a number of coefficients which need to be computed, based on some public properties inside a private class method. However, these properties are not set for some reason I don't quite understand. The method I have defined as:
methods (Access = private)
function obj = calcSchemeCoefficients (obj)
obj.lambda2 = (obj.gamma2*obj.k^2)/obj.h^2;
obj.mu = (obj.kappa*obj.k)/obj.h^2;
obj.mu2 = obj.mu^2;
obj.zeta = (4*obj.b2*obj.mu)/obj.kappa;
obj.den = 1+obj.b1*obj.k;
obj.a10 = (2-2*obj.lambda2-6*obj.mu2-obj.zeta)/obj.den;
obj.a11 = (obj.lambda2+4*obj.mu2+0.5*obj.zeta)/obj.den;
obj.a12 = -obj.mu2/obj.den;
obj.a20 = (-1+obj.zeta+obj.b1*obj.k)/obj.den;
obj.a21 = (-0.5*obj.zeta)/obj.den;
% this prints the correct result
fprintf('\nlambda2: %f\n', obj.lambda2);
end
end
However when I try to recall the property lambda2 for use in another (public) function, it doesn't seem to contain any value... I suspect I am missing some logic here, but I really have no clue what it could be.
Any help on this would be greatly appreciated
0 Comments
Accepted Answer
Daniel Shub
on 28 Nov 2011
My guess is you are not handling the returned object correctly. Are you using a value class or a handle class? What happens when you do:
obja.lambda2
objb = calcSchemeCoefficients(obja)
objb.lambda2
obja.lambda2
More Answers (0)
See Also
Categories
Find more on Software Development Tools in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!