MATLAB Object-Oriented Programming

(Joyce) #1

  • PreSet — Triggered before assigning the new property value within the set method

  • PostSet — Triggered after assigning the new property value within the set method


For information about using property events, see “Create Property Listeners” on page 11-
40.

Access Methods and Properties Containing Arrays


You can use array indexing with properties that contain arrays without interfering with
property set and get methods.

For indexed reference:

val = obj.PropName(n);

MATLAB calls the get method to get the referenced value.

For indexed assignment:

obj.PropName(n) = val;

MATLAB:


  • Invokes the get method to get the property value

  • Performs the indexed assignment on the returned property

  • Passes the new property value to the set method


Access Methods and Arrays of Objects


When reference or assignment occurs on an object array, MATLAB calls the set and get
methods in a loop. In this loop, MATLAB always passes scalar objects to set and get
methods.

Modify Property Values with Access Methods


Property access methods are useful in cases where you want to perform some additional
steps before assigning or returning a property value. For example, the Testpoint class
uses a property set method to check the range of a value. It then applies scaling if it is
within a particular range, and set it to NaN if it is not.

8 Properties — Storing Class Data

Free download pdf