FUNCTION REFERENCE

addlistener

Listen to an event of a handle object.

Listen to an event of a handle object.

Syntax

lh = addlistener(obj, 'EventName', @callback)

After addlistener(s, 'Changed', @(src, evt) disp(src.Value)), every notify(s, 'Changed') calls the callback with the object and an event data struct with the fields Source and EventName. Listeners run in the order they were added and go away with the object.

Example

exist('addlistener')   % 2

Differences from MATLAB: The listener returned is a struct (Source, EventName, Callback, Enabled), not an event.listener object: deleting it or setting Enabled does not stop the callback. Property events (PreSet, PostSet) and the listener(...) function are not supported yet.

These are the engine’s help pages. Each page keeps its compatibility notes. File operations are unavailable in the browser.