14 Examples of UIs Created Programmatically
end
- The localUpdatePlot function creates a plot in the axes. The localUpdatePlot
function gets the pop-up menu’s Value property to determine which plot the user
selected. - The default output argument is the handle of the main figure.
Define the Callbacks
This topic defines the callbacks that make the UI respond to user interactions. Because
the callback functions are nested inside the main function, they have access to all data
and components defined in the main function.
Although the UI has six components that are serviced by callbacks, there are only four
callback functions. This is because the Open menu item and the Open toolbar button
share the same callbacks. Similarly, the Print menu item and the Print toolbar button
share the same callbacks.
Update Button Callback
The hUpdateButtonCallback function services the Update push button. Clicking the
Update button triggers the execution of this callback function.
function hUpdateButtonCallback(hObject, eventdata)
% Callback function run when the Update button is pressed
localUpdatePlot();
end
Open Menu Item Callback
The hOpenMenuitemCallback function services the Open menu item and the Open
toolbar button. Selecting the menu item or clicking the toolbar button triggers the
execution of this callback function.
function hOpenMenuitemCallback(hObject,eventdata)
% Callback function run when the Open menu item is selected
file = uigetfile('*.m');
if ~isequal(file, 0)
open(file);
end