MATLAB Graphical User Interface
A graphical user interface (GUI) is a visual interface to a program. A good GUI can make applications more comfortable to use by providing them with a consistent appearance and with intuitive controls such as pushbuttons, edit boxes, list boxes, sliders, and menus.
How does Graphical User Interface Work?
A graphical user interface provides the client with a familiar environment in which to work. It contains push buttons, toggle buttons, lists, menus, text boxes, etc. GUIs are harder for the programmer because a GUI-based application must be prepared for mouse clicks (or possibly keyboard input) for any GUI item at any time. Such data are known as events, and a program that responds to events is said to be event-driven.
The three principal components required to create a MATLAB graphical user interface are:
Each element on a MATLAB GUI (pushbuttons, labels, edit boxes, etc.) is a graphical component. The method of components includes graphical controls (pushbuttons, togglebuttons, edit boxes, files, sliders, etc.) static components (text boxes), menus, toolbars, and axes. The function uicontrol creates graphical controls and text boxes, and menus are created by the functions uimenu and uicontextmenu. Toolbars are organized by function uitoolbar. Axes, which are used to show graphical data, are created by the function axes.
The components of a GUI must be organized within a container, which is a window on the computer screen. The most common container is a figure. A figure is a window on the laptop screen that has a title bar along the top, and that can optionally have menus connect. In the past, pictures have been created automatically whenever we plotted data.
Empty figures can be generated with the function figure, and they can be used to influence any combination of components and other containers. The different types of containers are panels (created by the function uipanel) and button groups (created by the function uibuttongroup). Panels can involve components or other containers, but they do not have a title bar and cannot have menus connect. Button groups are special panels that can handle groups of radio buttons or toggle buttons to provide that no more than one button in the group is on at any time.
Finally, there must be some way to act if a user clicks a mouse on a button or type information on a keyboard. A mouse clicks or a keypress is an event, and the MATLAB program must respond to each event if the program is to perform its function. For example, if a user clicks on a button, then that event must cause the MATLAB code that implements the role of the button to be executed. The code performed in response to an event is known as a callback. There must be a callback to implement the role of each graphical element on the GUI.
Components of GUI
To implement a simple calculator as a GUI (Graphical user interface).