MATLAB: MATLAB OOP – calling an object method from within another object method

objectoop

i created two objects from two different classes. how do i call one object from within the other?
any advice would be very much appreciated. thanks.

Best Answer

One way is via composition: (see http://en.wikipedia.org/wiki/Object_composition)
Let your two classes be class A and class B. Inside a property block of the class definition file for class A, include a variable, say bObj, that you intend to be an instance of class B. Then, in the constructor of class A, instantiate this instance of class B
bOjb = B(...)
Assuming that method m() of class B is public, invoke it anywhere in class definition file for class A with
bObj.m(...)