From: Hugo on 12 Jun 2010 23:48 Hi. I am making a small program using the OOP (Object-Oriented Programming) of Matlab. At some point, I need to compute T and A, which are properties of the class/object. They were defined as follows: properties (Dependent=true, SetAccess=private) T; A; end And this is what I understand... if I wanted to compute both T and A, I would need to use two getters. The problem with this implication is that since their computations are similar, the most convenient way to get them are through a function because they share the same parameters and procedure... T = T(beta, gamma, alpha, theta) A = A(beta, gamma, alpha, theta) In MATLAB format, it would become: methods ... function T=get.T(obj) [T A] = functionToGetTandA(beta, gamma, alpha, theta); end function A=get.A(obj) [T A] = functionToGetTandA(beta, gamma, alpha, theta); end ... end However, if the getters are implemented in such a way, the performance of the object will be strongly compromised, because the *same* procedure would be carried out twice. So, my question is: is there any way to compute them efficiently? Please, let me know If I was not clear. Many thanks in advance.
From: us on 13 Jun 2010 08:08 "Hugo " <hresquiveloa(a)gmail.com> wrote in message <hv1kdl$e98$1(a)fred.mathworks.com>... > Hi. I am making a small program using the OOP (Object-Oriented Programming) of Matlab. > > At some point, I need to compute T and A, which are properties of the class/object. They were defined as follows: > > properties (Dependent=true, SetAccess=private) > T; > A; > end > > > And this is what I understand... if I wanted to compute both T and A, I would need to use two getters. The problem with this implication is that since their computations are similar, the most convenient way to get them are through a function because they share the same parameters and procedure... > > T = T(beta, gamma, alpha, theta) > A = A(beta, gamma, alpha, theta) > > > In MATLAB format, it would become: > > methods > ... > function T=get.T(obj) > [T A] = functionToGetTandA(beta, gamma, alpha, theta); > end > > function A=get.A(obj) > [T A] = functionToGetTandA(beta, gamma, alpha, theta); > end > ... > end > > > However, if the getters are implemented in such a way, the performance of the object will be strongly compromised, because the *same* procedure would be carried out twice. > > So, my question is: is there any way to compute them efficiently? > > Please, let me know If I was not clear. > > Many thanks in advance. a hint (if i understand your pseudo-code): - you're mixing field names with var names... - one method is sufficient... us
From: Hugo on 13 Jun 2010 11:26 us, Thanks for reply... > you're mixing field names with var names... T and A are field names (properties); reason for which they should be treated in that way into the program. Although I can define them as one property (a property containing T and A), the idea is to treat them separately. > one method is sufficient... Could you explain me this hint better? If you can write it in pseudo-code, it will be greatly appreciated. Thanks!
From: Matt J on 13 Jun 2010 11:31 "Hugo " <hresquiveloa(a)gmail.com> wrote in message <hv1kdl$e98$1(a)fred.mathworks.com>... > Hi. I am making a small program using the OOP (Object-Oriented Programming) of Matlab. > > At some point, I need to compute T and A, which are properties of the class/object. They were defined as follows: > > properties (Dependent=true, SetAccess=private) > T; > A; > end > > > And this is what I understand... if I wanted to compute both T and A, I would need to use two getters. ======== No, I see no reason why you need get methods at all. Just initialize obj.T and obj.A in the constructor using [obj.T obj.A] = functionToGetTandA(beta, gamma, alpha, theta); Then you don't have to do anything else.
From: Hugo on 13 Jun 2010 14:23
Matt, Thanks for reply... And if beta and gamma are properties of the class/object??? I mean, [obj.T obj.A] = functionToGetTandA(obj.beta, obj.gamma, alpha, theta); How can I update T and A when beta and gamma are changed of value. PS: I should mention that possibility at the beginning. Sorry. |