Incorporating events in Matlab

Function to fire callbacks on variable and object changes/creations/deletions
1.1K Downloads
Updated 12 Oct 2006

View License

EVENTHANDLER allows a user to have one or more callback functions executed when an event of interest happens. Specifically, it can track the following events:

* Creation and deletion of variables, figures, and axes
* Deletion of generic graphics objects
* Changes in value of variables
* Changes in value of object parameters (including figures, axes, and any other graphics object having a handle), as well as sets of object parameters

A (clearly non-exhaustive) list of examples might include listeners that fire when:
* a figure is moved (or resized, but that already exists)
* an object is added/removed to a set of axes
* the text in a title/label/legend is changed
* a variable is cleared from memory
* etc.

In addition to calling functions when these events occur, event related information is retained (e.g. previous values, the name of the changed variable, etc.) and can be passed to the callback function.

Event listeners take wildcards as well as specific values, as well as exclusion lists (e.g. "fire this event when a variable is created that starts with the letter 'q' or contains an underscore, but only so long as it does not contain the letter 'u' or end with a digit").

Note: This function is not a true event handler (obviously, since that would require editing the underlying Matlab program). Rather, it involves a watching routine operating in the background. For this reason, it is not applicable to hardcore numerical programming where things change on the order of fractions of milliseconds. It is intended to be used with GUI's where human interaction requires at least fractions of seconds between events.

While I have tested this out reasonably thoroughly, I find that these kinds of functions often have weird bugs that only show up in unusual circumstances. Bug reports, suggestions for changes, as well as any other feedback would be greatly appreciated.

Cite As

Jeff Dunne (2024). Incorporating events in Matlab (https://www.mathworks.com/matlabcentral/fileexchange/12609-incorporating-events-in-matlab), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R14
Compatible with any release
Platform Compatibility
Windows macOS Linux
Categories
Find more on Specifying Target for Graphics Output in Help Center and MATLAB Answers

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!
Version Published Release Notes
1.0.0.0