This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Define and trigger events; create listeners that respond to events

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.


events Event names
handle.notify Notify listeners that event is occurring
handle.addlistener Create event listener
event.hasListener Determine if listeners exist for event


event.EventData Base class for event data
event.listener Class defining listener objects
event.PropertyEvent Data for property events
event.proplistener Define listener object for property events


Events and Listeners

Overview Events and Listeners

Use events and listeners to send and respond to messages.

Event and Listener Concepts

Events broadcast notifications to all registered listener and pass event-specific data to listener callback functions.

Events and Listeners Syntax

These code examples show how to define events and listeners

Event Attributes

Control access to events by setting event attributes.

Implementing Listeners

Listener Callback Syntax

Specify listener callbacks using function handles.

Callback Execution

Errors in listener callbacks do not prevent execution of other listeners. However, the order of listener execution is not defined.

Listener Lifecycle

MATLAB manages the lifecycle of listeners. For greater control of listener lifecycle, constructor listener objects using the event.listener constructor instead of addlistener.

Determine If Event Has Listeners

You can determine if there are listeners defined for a specific event and event source.

Property Listeners

Listen for Changes to Property Values

MATLAB defines pre and post set and get events for all properties.

Assignment When Property Value Unchanged

Prevent the triggering of property events when values do not change using the property AbortSet attribute.

Examples of Events and Listeners

Define Custom Event Data

Redefine the event data that MATLAB passes to listeners when an event is triggered.

Observe Changes to Property Values

Listeners can respond to changes in the value of properties using predefined property events.

Implement Property Set Listener

Listeners can respond to changes in property values before or after MATLAB assigns the value.

Techniques for Using Events and Listeners

This example shows how to enable and disable listener execution using context menus.

Was this topic helpful?