MATLAB Object-Oriented Programming

(Joyce) #1
mb1 = b1.findprop('myCoord');
mb1.SetMethod = @set_myCoord;

MATLAB calls the property set function whenever you set this property:

b1.myCoord = [1 2 3] % length must be two

Error using button.set_myCoord
myCoords require two values

You can set and get the property values only from within your property access methods.
You cannot call another function from the set or get method, and then attempt to access
the property value from that function.

Shared Set and Get Methods


You can assign the same function handle for the set or get method of multiple dynamic
properties. MATLAB passes only the object and the value to the assigned set function.

Reference or assignment to a property from within its set or get method does not invoke
the set or get method again. Therefore, if you use a handle to the same function for
multiple dynamic properties, that function is not invoked when accessing any of those
properties from within that function.

See Also


Related Examples



  • “Dynamic Properties — Adding Properties to an Instance” on page 8-69


8 Properties — Storing Class Data

Free download pdf