-1

See the code below:

Ex_ObjA.m

classdef Ex_ObjA

    properties
        a
    end

    methods
        function Obj=Ex_ObjA(t)
           Obj.a = t; 
        end
    end    
end

Ex_ObjBC.m

classdef Ex_ObjBC 

    properties  
        b 
    end

    properties (Dependent = true, SetAccess = public)
        c
    end    

    methods
        function Obj=Ex_ObjBC(t)
           Obj.b = t; 
        end

        function c=get.c(Obj,s1) % error: Get methods must have exactly one input
           c = Obj.b + s1.a;
        end
    end
end

I tried to do following:

s1 = Ex_ObjA(2);

s2 = Ex_ObjBC(3);

s2.c

Not successful, because "Get methods must have exactly one input". So I can pass the s1.a to Ex_ObjBC to get s1.c?

tshepang
  • 12,111
  • 21
  • 91
  • 136
  • 1
    You will need to store the object of the class `Ex_ObjA.m` in the `Ex_ObjBC.m` and use it on the Dependent get method. You could make it only one class also. Another solution is to make a function instead of a Dependent property. – Werner Oct 02 '13 at 04:27

1 Answers1

0

c isn't really a Dependent property, it's the result of a calculation. Just get rid of the property c, and have a method c = calculatec(Obj, s1) that executes the same code as you have now.

Sam Roberts
  • 23,951
  • 1
  • 40
  • 64
  • I did that define the function like c=getc(Obj,s1) and call it using s2.getc(s1). It works but I do not understand why the inputs have to be like that, one is (Obj,s1) and the caller is getc(s1) - not the same. I know it works but why? Seems Obj is internal input of s2. Thanks... – user2773103 Oct 02 '13 at 15:24