MATLAB Object-Oriented Programming

(Joyce) #1

Assignment When Property Value Is Unchanged


In this section...
“AbortSet When Value Does Not Change” on page 11-44
“How MATLAB Compares Values” on page 11-44
“When to Use AbortSet” on page 11-45
“Implement AbortSet” on page 11-45
“Using AbortSet with Property Validation” on page 11-47

AbortSet When Value Does Not Change


When you set a property value, MATLAB triggers the property PreSet and PostSet
events, invokes the property set method (if one is defined), and sets the property value.
These actions occur even when the current value of the property is the same as the new
value.

You can prevent these actions by setting the property's AbortSet attribute to true.
When AbortSet is enabled, MATLAB compares the current property value to the new
value being assigned to the property. If the new value is the same as the current value,
MATLAB does not:


  • Set the property value.

  • Trigger the PreSet and PostSet events.

  • Call the property set method, if one exists.


To compare values, MATLAB must get the current value of the property. Getting the
current value causes the property get method (get.Property) to execute, if one exists.
Any errors that occur when calling the property get method are visible to the user, even if
MATLAB does not change the current value.

How MATLAB Compares Values


MATLAB uses the isequal function to determine if the current value of the property is
the same as the new value. To determine if specific values evaluate as equal when using
the AbortSet attribute, see the isequal function documentation or any isequal
method overloaded for the class of the property value.

11 Events — Sending and Responding to Messages

Free download pdf