0% found this document useful (0 votes)
84 views20 pages

Graphical User Interface (GUI) in Matlab: Dr. P. Purkait

The document discusses graphical user interfaces (GUIs) in MATLAB. It explains that a GUI uses components like buttons, lists and plots to enable interactive tasks without requiring the user to write scripts or type commands. Each GUI component is associated with callback functions that execute when the user interacts with that component. The GUIDE tool is used to layout and program GUIs by placing components, assigning identifiers, and writing the callback code.

Uploaded by

ud54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views20 pages

Graphical User Interface (GUI) in Matlab: Dr. P. Purkait

The document discusses graphical user interfaces (GUIs) in MATLAB. It explains that a GUI uses components like buttons, lists and plots to enable interactive tasks without requiring the user to write scripts or type commands. Each GUI component is associated with callback functions that execute when the user interacts with that component. The GUIDE tool is used to layout and program GUIs by placing components, assigning identifiers, and writing the callback code.

Uploaded by

ud54
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 20

Graphical User Interface

(GUI)
in
MATLAB

Dr. P. Purkait
GUI
• (GUI) is a graphical display
• Enable user to perform interactive
tasks
• User of the GUI does not have to
create a script
• User of the GUI does not have to
type commands at the command line
• The GUI components can be menus,
toolbars, push buttons, radio
buttons, list boxes, and sliders
2
Example

• The GUI contains


– One axes (plot)
– Three Push Buttons
– One List Box
– One Static test Box 3
How Does a GUI Work?

• Each component (button, plot, list box etc)


is associated with one or more user-
written routines (functions) known as
callbacks.

• The execution of each callback is triggered


by a particular user action such as a
button push or mouse click.

• You, as the creator of the GUI will have to


write these callbacks.
4
GUIDE
GUI Development Environment
• GUIDE, provides a set of tools for creating
graphical user interfaces (GUIs)

• These tools simplify the process of laying


out and programming GUIs

• The Layout Editor is the control panel for


GUIDE

• To start the Layout Editor, use the guide


command in the MATLAB command
window 5
GUIDE Tools
Menu Property
Alignment Editor Inspector Object
Tool
Browser Activate
Figure
Component
Palette

Layout Area

Figure Resize Tab

6
Laying Out a GUI – The layout
editor
• Type guide in the command prompt

7
Placing a Component in the Layout Area
• Available Components

• Push Button
Component
palette with • Radio Button
names
• Check Box
• Edit Text Box

Component • Static Text Box


palette without • Slider
names
• List Box
• Popup Menu
• Axes

8
Example of GUI in the Layout
Editor

9
Assigning an Identifier to Each
Component
Use the Tag property to assign each component a
unique meaningful identifier

• Double click on the component for which you need to open the Property
Inspector

• In the Property Inspector, select Tag and then replace the value with the string
you want to use as the identifier

• In the figure above, the Tag is set to Button1


10
Adding Text to the Components
Use the String property to assign each
component a unique meaningful text

• In the Property Inspector, select String and then replace the


value with the string you want to use as the identifier

• In the figure above, the String is set to Test Button


11
Assignment 1
• Change the names of the different components in
the example figure, add texts to list box and popup
menu

12
Alignment Tool
• The Alignment Tool
enables to position
objects with respect to
each other and to
adjust the spacing
between selected
objects

• The specified alignment


operations apply to all
components that are
selected when you
press the Apply button.
13
The Property Inspector –
Setting Component Properties
• Double-clicking
on a component
in the Layout
Editor

• Selecting
Property
Inspector in the
Tools menu

• Right-clicking on
a component
and selecting
Inspect
Properties from
the menu

14
Assignment 2
• Open the Properties of PUSH
BUTTON and check / change its
properties

15
Saving the GUI
• A FIG-file, with extension .fig, that
contains a complete description of
the GUI layout and the GUI
components

• An M-file, with extension .m, that


contains the code that controls the
GUI, including the callbacks for its
components.
16
Running the GUI

• From the GUIDE Layout Editor


– Clicking the Activate Figure icon
• From the Command Line
– Enter the name of its M-file
• From an M-file Script
– Clicking the Run icon

17
Programming the GUI
• callbacks

– A callback is a function that you write and


associate with a specific GUI component or
with the GUI figure
– It controls GUI or component behavior by
performing some action in response to an
event for its component

• callbacks are written / edited in


the .m file associated with the GUI
18
Format and syntax for callbacks
function varargout = pushbutton1_Callback(h, eventdata, handles, varargin)

• h is the callback object's handle

• eventdata is empty, but reserved for future use

• handles is a structure containing handles of


components in GUI using tags as fieldnames, e.g.
handles.figure1, handles.slider2

• varargin contains any extra arguments you have


passed to the callback.
19
Examples

• Push Button
• Edit Text
• Radio Button
• Check Box
• Slider
• List Box
• Pop-Up Menu
• Axes
20

You might also like