|On this page…|
A callback is a function that executes when a specific event occurs on a graphics object. You specify a callback by setting the appropriate property of the object. This section describes the events (specified via properties) for which you can define callbacks. See Function Handle Callbacks for information on how to define callbacks.
Note: When you call a plotting function, such as plot, bar, contour, and so on, MATLAB® creates new graphics objects and resets most figure and axes properties. Therefore, callback functions you have defined for graphics objects can be removed. See Controlling Graphics Output for more information.
All graphics objects have three properties for which you can define callback routines:
ButtonDownFcn — Executes when you click the left mouse button while the cursor is over the object or is within a few pixels of the object.
CreateFcn — Executes during object creation after you set all properties.
DeleteFcn — Executes just before deleting the object.
User interface objects (e.g., uicontrol and uimenu) have a Callback property through which you define the function to execute when you activate these devices (e.g., click a push button or select a menu).
Figures have additional properties that execute callback routines with the appropriate user action. Only the CloseRequestFcn property has a callback defined by default:
KeyPressFcn — Executes when you press a key while the cursor is within the figure window.
ResizeFcn — Executes when you resize the figure window.
WindowButtonDownFcn — Executes when you click a mouse button while the cursor is over the figure background, a disabled uicontrol, or the axes background.
WindowButtonMotionFcn — Executes when you move the mouse button within the figure window (but not over menus or title bar).
WindowButtonUpFcn — Executes when you release the mouse button, after having pressed the mouse button within the figure.