Events are notices broadcast when some change or action occurs involving an object. Listeners define functions that execute when specific events occur. Classes can define and trigger events. MATLAB® can trigger predefined events when code accesses object properties.
Use events and listeners to send and respond to messages.
Events broadcast notifications to all registered listener and pass event-specific data to listener callback functions.
These code examples show how to define events and listeners
Control access to events by setting event attributes.
Specify listener callbacks using function handles.
Errors in listener callbacks do not prevent execution of other listeners. However, the order of listener execution is not defined.
MATLAB manages the lifecycle of listeners. For
greater control of listener lifecycle, constructor listener objects
event.listener constructor instead of
You can determine if there are listeners defined for a specific event and event source.
Redefine the event data that MATLAB passes to listeners when an event is triggered.
Listeners can respond to changes in the value of properties using predefined property events.
Listeners can respond to changes in property values before or after MATLAB assigns the value.
This example shows how to enable and disable listener execution using context menus.