SlideShare a Scribd company logo
3
Most read
4
Most read
9
Most read
Gui in Matlab
Group : 4
Topics
About gui
How to create gui with Guide
How to Create a Simple GUI
Programmatically
What Is a GUI?
A graphical user interface (GUI) is a graphical display in one or more
windows containing controls, called components, that enable a user to perform
interactive tasks.
The user of the GUI does not have to create a script or
type commands at the command line to accomplish the tasks.
Unlike coding
programs to accomplish tasks, the user of a GUI need not understand the
details of how the tasks are performed.
GUI components can include menus, toolbars, push buttons, radio buttons,
list boxes, and sliders—just to name a few. GUIs created using MATLAB
tools can also perform any type of computation, read and write data files,
communicate with other GUIs, and display data as tables or as plots.
Sample Gui figure
What in pervious figure ?
The GUI contains
•An axes component
•Apop-up menu listing three data sets that correspond to MATLAB
functions: peaks, membrane,andsinc
•Astatic text component to label the pop-up menu
•Three buttons that provide different kinds of plots: surface, mesh, and
contour
When you click a push button, the axes component displays the selected data
set using the specified type of 3-D plot
Where Do I Start?
Before starting to construct a GUI you have to design it. At a minimum,
You have to decide:
•Who the GUI users will be
•What you want the GUI to do
•How users will interact with the GUI
•What components the GUI requires to function
When designing any software, you need to understand the purposes a new
GUI needs to satisfy. You or the GUI’s potential users should document user
requirements as completely and precisely as possible before starting or build
it. This includes specifying the inputs, outputs, displays, and behaviors of the
GUI and the application it controls. After you design a GUI, you need to
program each of its controls to operate correctly and consistently. Finally, you
should test the completed or prototype GUI to make sure that it behaves as
intended under realistic conditions. (Or better yet, have someone else test it.)
If testing reveals design or programming flaws, iterate the design until the
GUI works to your satisfaction. The following diagram illustrates the main
aspects of this process.
Ways to Build MATLAB GUI
Use GUIDE (GUI Development Environment), an interactive GUI
construction kit.
-------------------------------------------------------------------
•Create code files that generate GUIs as functions or scripts
(programmatic GUI construction).
What Is GUIDE?
GUIDE, the MATLAB Graphical User Interface Development Environment,
provides a set of tools for creating graphical user interfaces (GUIs).
These
tools greatly simplify the process of laying out and programming GUIs.
Type guide to open
Lay Out the Simple GUI in GUIDE
Open a New GUI in the GUIDE Layout Editor
1-Start GUIDE by typing guide at the MATLAB prompt.
Lay Out the Simple GUI in GUIDE
Gui in matlab :
Gui in matlab :
1-Add the three push buttons to the GUI. Select the push button tool from
the component palette at the left side of the Layout Editor and drag it into
the layout area. Create three buttons, positioning them approximately as
Shown in the following figure
2-Add the remaining components to the GUI.
•Astatic text area
•A pop-up menu
•An axes
Arrange the components as shown in the previous figure. Resize the axes
component to approximately 2-by-2 inches.
Align the Components
If several components have the same parent, you can use the Alignment Tool
to align them to one another. To align the three push buttons:
1Select all three push buttons by pressingCtrland clicking them.
2SelectTools > Align Objects
3-Make these settings in the Alignment Tool:
•Left-aligned in the horizontal direction.
•20 pixels spacing between push buttons in the vertical direction.
4- click ok 4
Label the Push Buttons
SelectView > Property Inspector.
Align the Components
If several components have the same parent, you can use the Alignment Tool
to align them to one another. To align the three push buttons:
1-Select all three push buttons by pressing Ctrl and clicking them.
2-SelectTools > Align Objects.
3-Make these settings in the Alignment Tool:
•Left-aligned in the horizontal direction.
•20 pixels spacing between push buttons in the vertical direction
How to Create a Simple
GUI Programmatically
Create the Simple Programmatic GUI Code File
Almost all MATLAB functions work in GUIs. Many functions add components
to GUIs or modify their behavior, others assist in laying out GUIs, and still
others manage data within GUIs.
When you create the simple programmatic GUI code file, you start by creating
a function file (as opposed to a script file, which contains a sequence of
MATLAB commands but does not define functions).
1-At the MATLAB prompt, type edit. MATLAB opens a blank document in
the Editor.
2-Type the following statement into the Editor. This function statement
is the first line in the file.
function simple_gui2
3-Type these comments into the file following the function statement. They
display at the command line in response to the help command. Follow
them by a blank line, which MATLAB requires to terminate the help text.
% SIMPLE_GUI2 Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
(Leave a blank line here)
4-Add an end statement at the end of the file. This end statement matches
The function statement. Your file now looks like this.
function simple_gui2
% SIMPLE_GUI2 Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
end
5-Save the file in your current folder or at a location that is on your MATLAB
path.
The next section, “Lay Out the Simple Programmatic GUI” on page 3-6, shows
you how to add components to your GUI.
The next section, “Lay Out the Simple Programmatic GUI” on page 3-6, shows
you how to add components to your GUI.
Create a Figure for a Programmatic GUI
In MATLAB software, a GUI is a figure. This first step creates the figure and
Positionsiton the screen.It also makes the GUI invisible so that the GUI
user cannot see the components being added or initialized. When the GUI has
all its components and is initialized, the example makes it visible. Add the
following lines before the end statement currently in your file:
% Create and then hide the GUI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450,285]);
The call to the figure function uses two property/value pairs. The Position
property is a four-element vector that specifies the location of the GUI on the
screen and its size: [distance from left, distance from bottom, width, height].
Default units are pixels.
The next topic, “Add Components to a Programmatic GUI” , shows
you how to add the push buttons, axes, and other components to the GUI
1-Add the three push buttons to your GUI by adding these statements to your
code file following the call tofigure.
% Construct the components.
hsurf = uicontrol('Style','pushbutton',...
'String','Surf','Position',[315,220,70,25]);
hmesh = uicontrol('Style','pushbutton',...
'String','Mesh','Position',[315,180,70,25]);
hcontour = uicontrol('Style','pushbutton',...
'String','Countour','Position',[315,135,70,25]);
These statements use the uicontrol function to create the push buttons.
Each statement uses a series of property/value pairs to define a push
button.
2-Add the pop-up menu and its label to your GUI by adding these statements
to the code file following the push button definitions.
hpopup = uicontrol('Style','popupmenu',...
'String',{'Peaks','Membrane','Sinc'},...
'Position',[300,50,100,25]);
htext = uicontrol('Style','text','String','Select Data',...
'Position',[325,90,60,15]);
3-Add the axes to the GUI by adding this statement to the code file. Set
theUnitsproperty to pixels so that it has the same units as the other
components.
ha = axes('Units','pixels','Position',[50,60,200,185]);
4-Align all components except the axes along their centers with the
following
statement. Add it to the code file following all the component
definitions.
align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None');
5-Make your GUI visible by adding this command following thealign
command.
%Make the GUI visible.
set(f,'Visible','on')
6-This is what your code file should now look like:
6-This is what your code file should now look like:
function simple_gui2
% SIMPLE_GUI2 Select a data set from the pop-up menu, then
% click one of the plot-type push buttons. Clicking the button
% plots the selected data in the axes.
% Create and then hide the GUI as it is being constructed.
f = figure('Visible','off','Position',[360,500,450,285]);
% Construct the components.
hsurf = uicontrol('Style','pushbutton','String','Surf',...
'Position',[315,220,70,25]);
hmesh = uicontrol('Style','pushbutton','String','Mesh',...
'Position',[315,180,70,25]);
hcontour = uicontrol('Style','pushbutton',...
'String','Countour',...
'Position',[315,135,70,25]);
htext = uicontrol('Style','text','String','Select Data',...
'Position',[325,90,60,15]);
hpopup = uicontrol('Style','popupmenu',...
% Construct the components.
hsurf = uicontrol('Style','pushbutton','String','Surf',...
'Position',[315,220,70,25]);
hmesh = uicontrol('Style','pushbutton','String','Mesh',...
'Position',[315,180,70,25]);
hcontour = uicontrol('Style','pushbutton',...
'String','Countour',...
'Position',[315,135,70,25]);
htext = uicontrol('Style','text','String','Select Data',...
'Position',[325,90,60,15]);
hpopup = uicontrol('Style','popupmenu',...
'String',{'Peaks','Membrane','Sinc'},...
'Position',[300,50,100,25]);
ha = axes('Units','Pixels','Position',[50,60,200,185]);
align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None');
%Make the GUI visible.
set(f,'Visible','on')
end

More Related Content

PPTX
Matlab GUI
DataminingTools Inc
 
PPT
Time Division Multiplexing
Spandit Lenka
 
PPT
wavelet packets
ajayhakkumar
 
PDF
token bus
iamvisakh
 
PPTX
Image Enhancement using Frequency Domain Filters
Karthika Ramachandran
 
PPTX
Binary numbers
SabahtHussein
 
PPT
Fidelity criteria in image compression
KadamPawan
 
Time Division Multiplexing
Spandit Lenka
 
wavelet packets
ajayhakkumar
 
token bus
iamvisakh
 
Image Enhancement using Frequency Domain Filters
Karthika Ramachandran
 
Binary numbers
SabahtHussein
 
Fidelity criteria in image compression
KadamPawan
 

What's hot (20)

PPTX
Information Theory and coding - Lecture 2
Aref35
 
PPTX
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 22-30)
Adnan Zafar
 
PPTX
Connecting devices
Himanshu Shekhar
 
PPTX
Edge detection
Ishraq Al Fataftah
 
PPTX
Image enhancement
Ayaelshiwi
 
PPTX
Edge Detection using Hough Transform
Mrunal Selokar
 
PPTX
Curve fitting of exponential curve
Divyang Rathod
 
DOC
Digital Signal Processing Lab Manual ECE students
UR11EC098
 
PPTX
Introduction of tcp, ip & udp
rahul kundu
 
PPT
Chapter 3: Data & Signals
Shafaan Khaliq Bhatti
 
PPTX
Synchronous and Asynchronous Transmission
Adeel Rasheed
 
PPTX
WIRELESS ATM BY SAIKIRAN PANJALA
Saikiran Panjala
 
PPT
Chapter 2 Image Processing: Pixel Relation
Varun Ojha
 
PDF
Simulation of Wireless Communication Systems
Bernd-Peter Paris
 
PDF
Decoders
Re Man
 
PPTX
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 16-21)
Adnan Zafar
 
PPTX
Multiplexers
DrSonali Vyas
 
PPTX
Am modulator square law modulator
Learn By Watch
 
PPTX
Channel capacity
PALLAB DAS
 
PPT
Matlab Tutorial.ppt
RaviMuthamala1
 
Information Theory and coding - Lecture 2
Aref35
 
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 22-30)
Adnan Zafar
 
Connecting devices
Himanshu Shekhar
 
Edge detection
Ishraq Al Fataftah
 
Image enhancement
Ayaelshiwi
 
Edge Detection using Hough Transform
Mrunal Selokar
 
Curve fitting of exponential curve
Divyang Rathod
 
Digital Signal Processing Lab Manual ECE students
UR11EC098
 
Introduction of tcp, ip & udp
rahul kundu
 
Chapter 3: Data & Signals
Shafaan Khaliq Bhatti
 
Synchronous and Asynchronous Transmission
Adeel Rasheed
 
WIRELESS ATM BY SAIKIRAN PANJALA
Saikiran Panjala
 
Chapter 2 Image Processing: Pixel Relation
Varun Ojha
 
Simulation of Wireless Communication Systems
Bernd-Peter Paris
 
Decoders
Re Man
 
Communication Systems_B.P. Lathi and Zhi Ding (Lecture No 16-21)
Adnan Zafar
 
Multiplexers
DrSonali Vyas
 
Am modulator square law modulator
Learn By Watch
 
Channel capacity
PALLAB DAS
 
Matlab Tutorial.ppt
RaviMuthamala1
 
Ad

Viewers also liked (20)

PPTX
GUI in Matlab - 1
Sahil Potnis
 
PDF
Matlab GUI
Omair Imtiaz Ansari
 
PPTX
Graphical User Interface (Gui)
Bilal Amjad
 
PPT
GUI -THESIS123
Aparna Reddy
 
PPTX
Muhammad rizwan aqeel rlp.ppt
M Rizwan Aqeel
 
PDF
Natural Language Checking with Program Checking Tools
Lukas Renggli
 
PDF
TIP_E-Conversion_System
Rana Saini
 
DOCX
MATLAB TRAINING COURSE IN CHENNAI@MAASTECH/MATLAB
ASHOKKUMAR RAMAR
 
PPTX
Presen_Segmentation
Vikas Goyal
 
PPTX
Text detection and recognition from natural scenes
hemanthmcqueen
 
PDF
DSBW Final Exam (Spring Sementer 2010)
Carles Farré
 
PPTX
Error control coding
Mohammad Bappy
 
PPTX
Lecture 09: Localization and Mapping III
University of Colorado at Boulder
 
PPT
Devanagari Character Recognition
Pulkit Goyal
 
PPS
Matlab Untuk Pengolahan Citra
arifgator
 
DOCX
Modul praktikum pengolahan citra digital
Dhanar Intan Surya Saputra
 
PDF
Praktik dengan matlab
Syafrizal
 
PDF
Neural network in matlab
Fahim Khan
 
PDF
Pengolahan Citra Digital Dengan Menggunakan MATLAB
Simesterious TheMaster
 
PDF
Advanced MATLAB Tutorial for Engineers & Scientists
Ray Phan
 
GUI in Matlab - 1
Sahil Potnis
 
Graphical User Interface (Gui)
Bilal Amjad
 
GUI -THESIS123
Aparna Reddy
 
Muhammad rizwan aqeel rlp.ppt
M Rizwan Aqeel
 
Natural Language Checking with Program Checking Tools
Lukas Renggli
 
TIP_E-Conversion_System
Rana Saini
 
MATLAB TRAINING COURSE IN CHENNAI@MAASTECH/MATLAB
ASHOKKUMAR RAMAR
 
Presen_Segmentation
Vikas Goyal
 
Text detection and recognition from natural scenes
hemanthmcqueen
 
DSBW Final Exam (Spring Sementer 2010)
Carles Farré
 
Error control coding
Mohammad Bappy
 
Lecture 09: Localization and Mapping III
University of Colorado at Boulder
 
Devanagari Character Recognition
Pulkit Goyal
 
Matlab Untuk Pengolahan Citra
arifgator
 
Modul praktikum pengolahan citra digital
Dhanar Intan Surya Saputra
 
Praktik dengan matlab
Syafrizal
 
Neural network in matlab
Fahim Khan
 
Pengolahan Citra Digital Dengan Menggunakan MATLAB
Simesterious TheMaster
 
Advanced MATLAB Tutorial for Engineers & Scientists
Ray Phan
 
Ad

Similar to Gui in matlab : (20)

PPTX
intro_gui
filipb2
 
PDF
Tutorial MATLAB GUI. MATLAB GUI (G hi l U I t f ) T t i l f B i MATLAB GUI (G...
thinhttst2003
 
PDF
Vb%20 tutorial
Satya Prakash
 
PPT
Howtouse gui _sinmatlab
M Ahsan Khan
 
PPTX
Using prime[31] to connect your unity game to azure mobile services
David Voyles
 
PDF
2 Module - Operating Systems Configuration and Use by Mark John Lado
Mark John Lado, MIT
 
PDF
GTK+ 2.0 App - Icon Chooser
William Lee
 
PDF
GUI ICGST VERY USEFULl.pdf
AshaLatha456489
 
PPT
Google calendar integration in iOS app
Ketan Raval
 
PDF
Software engineering modeling lab lectures
marwaeng
 
PPTX
User Tutorial
Chris Ford
 
PDF
Swift
Larry Ball
 
PDF
Programming Without Coding Technology (PWCT) - Simple GUI Application
Mahmoud Samir Fayed
 
PPTX
Visual basic
mafffffe19
 
PDF
Publication Non Visual Components
satyres
 
PDF
ArduinoWorkshop2.pdf
PedramKashiani
 
DOC
222066369 clad-study-guide
homeworkping9
 
PPTX
Model builder in ARC GIS
KU Leuven
 
PPTX
Matlab Assignment Help
Matlab Assignment Experts
 
PDF
Programming Without Coding Technology (PWCT) - Center Window
Mahmoud Samir Fayed
 
intro_gui
filipb2
 
Tutorial MATLAB GUI. MATLAB GUI (G hi l U I t f ) T t i l f B i MATLAB GUI (G...
thinhttst2003
 
Vb%20 tutorial
Satya Prakash
 
Howtouse gui _sinmatlab
M Ahsan Khan
 
Using prime[31] to connect your unity game to azure mobile services
David Voyles
 
2 Module - Operating Systems Configuration and Use by Mark John Lado
Mark John Lado, MIT
 
GTK+ 2.0 App - Icon Chooser
William Lee
 
GUI ICGST VERY USEFULl.pdf
AshaLatha456489
 
Google calendar integration in iOS app
Ketan Raval
 
Software engineering modeling lab lectures
marwaeng
 
User Tutorial
Chris Ford
 
Swift
Larry Ball
 
Programming Without Coding Technology (PWCT) - Simple GUI Application
Mahmoud Samir Fayed
 
Visual basic
mafffffe19
 
Publication Non Visual Components
satyres
 
ArduinoWorkshop2.pdf
PedramKashiani
 
222066369 clad-study-guide
homeworkping9
 
Model builder in ARC GIS
KU Leuven
 
Matlab Assignment Help
Matlab Assignment Experts
 
Programming Without Coding Technology (PWCT) - Center Window
Mahmoud Samir Fayed
 

Recently uploaded (20)

PDF
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
PDF
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
PDF
Landforms and landscapes data surprise preview
jpinnuck
 
PPTX
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
PPTX
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
PPTX
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
PDF
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
PDF
Sunset Boulevard Student Revision Booklet
jpinnuck
 
PPTX
How to Manage Global Discount in Odoo 18 POS
Celine George
 
PDF
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
DOCX
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PDF
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
PDF
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
PPTX
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
PDF
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
Sandeep Swamy
 
PPTX
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
PPTX
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
PPTX
Strengthening open access through collaboration: building connections with OP...
Jisc
 
PPTX
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
PPTX
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 
What is CFA?? Complete Guide to the Chartered Financial Analyst Program
sp4989653
 
The Final Stretch: How to Release a Game and Not Die in the Process.
Marta Fijak
 
Landforms and landscapes data surprise preview
jpinnuck
 
Open Quiz Monsoon Mind Game Prelims.pptx
Sourav Kr Podder
 
Open Quiz Monsoon Mind Game Final Set.pptx
Sourav Kr Podder
 
Dakar Framework Education For All- 2000(Act)
santoshmohalik1
 
3.The-Rise-of-the-Marathas.pdfppt/pdf/8th class social science Exploring Soci...
Sandeep Swamy
 
Sunset Boulevard Student Revision Booklet
jpinnuck
 
How to Manage Global Discount in Odoo 18 POS
Celine George
 
Electricity-Magnetic-and-Heating-Effects 4th Chapter/8th-science-curiosity.pd...
Sandeep Swamy
 
UPPER GASTRO INTESTINAL DISORDER.docx
BANDITA PATRA
 
PG-BPSDMP 2 TAHUN 2025PG-BPSDMP 2 TAHUN 2025.pdf
AshifaRamadhani
 
The Picture of Dorian Gray summary and depiction
opaliyahemel
 
Introduction and Scope of Bichemistry.pptx
shantiyogi
 
5.Universal-Franchise-and-Indias-Electoral-System.pdfppt/pdf/8th class social...
Sandeep Swamy
 
family health care settings home visit - unit 6 - chn 1 - gnm 1st year.pptx
Priyanshu Anand
 
TEF & EA Bsc Nursing 5th sem.....BBBpptx
AneetaSharma15
 
Strengthening open access through collaboration: building connections with OP...
Jisc
 
HISTORY COLLECTION FOR PSYCHIATRIC PATIENTS.pptx
PoojaSen20
 
Tips Management in Odoo 18 POS - Odoo Slides
Celine George
 

Gui in matlab :

  • 2. Topics About gui How to create gui with Guide How to Create a Simple GUI Programmatically
  • 3. What Is a GUI? A graphical user interface (GUI) is a graphical display in one or more windows containing controls, called components, that enable a user to perform interactive tasks. The user of the GUI does not have to create a script or type commands at the command line to accomplish the tasks. Unlike coding programs to accomplish tasks, the user of a GUI need not understand the details of how the tasks are performed. GUI components can include menus, toolbars, push buttons, radio buttons, list boxes, and sliders—just to name a few. GUIs created using MATLAB tools can also perform any type of computation, read and write data files, communicate with other GUIs, and display data as tables or as plots.
  • 5. What in pervious figure ? The GUI contains •An axes component •Apop-up menu listing three data sets that correspond to MATLAB functions: peaks, membrane,andsinc •Astatic text component to label the pop-up menu •Three buttons that provide different kinds of plots: surface, mesh, and contour When you click a push button, the axes component displays the selected data set using the specified type of 3-D plot
  • 6. Where Do I Start? Before starting to construct a GUI you have to design it. At a minimum, You have to decide: •Who the GUI users will be •What you want the GUI to do •How users will interact with the GUI •What components the GUI requires to function When designing any software, you need to understand the purposes a new GUI needs to satisfy. You or the GUI’s potential users should document user requirements as completely and precisely as possible before starting or build it. This includes specifying the inputs, outputs, displays, and behaviors of the GUI and the application it controls. After you design a GUI, you need to program each of its controls to operate correctly and consistently. Finally, you should test the completed or prototype GUI to make sure that it behaves as intended under realistic conditions. (Or better yet, have someone else test it.) If testing reveals design or programming flaws, iterate the design until the GUI works to your satisfaction. The following diagram illustrates the main aspects of this process.
  • 7. Ways to Build MATLAB GUI Use GUIDE (GUI Development Environment), an interactive GUI construction kit. ------------------------------------------------------------------- •Create code files that generate GUIs as functions or scripts (programmatic GUI construction).
  • 8. What Is GUIDE? GUIDE, the MATLAB Graphical User Interface Development Environment, provides a set of tools for creating graphical user interfaces (GUIs). These tools greatly simplify the process of laying out and programming GUIs. Type guide to open Lay Out the Simple GUI in GUIDE Open a New GUI in the GUIDE Layout Editor 1-Start GUIDE by typing guide at the MATLAB prompt.
  • 9. Lay Out the Simple GUI in GUIDE
  • 12. 1-Add the three push buttons to the GUI. Select the push button tool from the component palette at the left side of the Layout Editor and drag it into the layout area. Create three buttons, positioning them approximately as Shown in the following figure 2-Add the remaining components to the GUI. •Astatic text area •A pop-up menu •An axes Arrange the components as shown in the previous figure. Resize the axes component to approximately 2-by-2 inches. Align the Components If several components have the same parent, you can use the Alignment Tool to align them to one another. To align the three push buttons: 1Select all three push buttons by pressingCtrland clicking them. 2SelectTools > Align Objects
  • 13. 3-Make these settings in the Alignment Tool: •Left-aligned in the horizontal direction. •20 pixels spacing between push buttons in the vertical direction. 4- click ok 4 Label the Push Buttons SelectView > Property Inspector.
  • 14. Align the Components If several components have the same parent, you can use the Alignment Tool to align them to one another. To align the three push buttons: 1-Select all three push buttons by pressing Ctrl and clicking them. 2-SelectTools > Align Objects. 3-Make these settings in the Alignment Tool: •Left-aligned in the horizontal direction. •20 pixels spacing between push buttons in the vertical direction
  • 15. How to Create a Simple GUI Programmatically Create the Simple Programmatic GUI Code File Almost all MATLAB functions work in GUIs. Many functions add components to GUIs or modify their behavior, others assist in laying out GUIs, and still others manage data within GUIs. When you create the simple programmatic GUI code file, you start by creating a function file (as opposed to a script file, which contains a sequence of MATLAB commands but does not define functions).
  • 16. 1-At the MATLAB prompt, type edit. MATLAB opens a blank document in the Editor. 2-Type the following statement into the Editor. This function statement is the first line in the file. function simple_gui2 3-Type these comments into the file following the function statement. They display at the command line in response to the help command. Follow them by a blank line, which MATLAB requires to terminate the help text. % SIMPLE_GUI2 Select a data set from the pop-up menu, then % click one of the plot-type push buttons. Clicking the button % plots the selected data in the axes. (Leave a blank line here)
  • 17. 4-Add an end statement at the end of the file. This end statement matches The function statement. Your file now looks like this. function simple_gui2 % SIMPLE_GUI2 Select a data set from the pop-up menu, then % click one of the plot-type push buttons. Clicking the button % plots the selected data in the axes. end 5-Save the file in your current folder or at a location that is on your MATLAB path. The next section, “Lay Out the Simple Programmatic GUI” on page 3-6, shows you how to add components to your GUI. The next section, “Lay Out the Simple Programmatic GUI” on page 3-6, shows you how to add components to your GUI.
  • 18. Create a Figure for a Programmatic GUI In MATLAB software, a GUI is a figure. This first step creates the figure and Positionsiton the screen.It also makes the GUI invisible so that the GUI user cannot see the components being added or initialized. When the GUI has all its components and is initialized, the example makes it visible. Add the following lines before the end statement currently in your file: % Create and then hide the GUI as it is being constructed. f = figure('Visible','off','Position',[360,500,450,285]); The call to the figure function uses two property/value pairs. The Position property is a four-element vector that specifies the location of the GUI on the screen and its size: [distance from left, distance from bottom, width, height]. Default units are pixels. The next topic, “Add Components to a Programmatic GUI” , shows you how to add the push buttons, axes, and other components to the GUI
  • 19. 1-Add the three push buttons to your GUI by adding these statements to your code file following the call tofigure. % Construct the components. hsurf = uicontrol('Style','pushbutton',... 'String','Surf','Position',[315,220,70,25]); hmesh = uicontrol('Style','pushbutton',... 'String','Mesh','Position',[315,180,70,25]); hcontour = uicontrol('Style','pushbutton',... 'String','Countour','Position',[315,135,70,25]); These statements use the uicontrol function to create the push buttons. Each statement uses a series of property/value pairs to define a push button.
  • 20. 2-Add the pop-up menu and its label to your GUI by adding these statements to the code file following the push button definitions. hpopup = uicontrol('Style','popupmenu',... 'String',{'Peaks','Membrane','Sinc'},... 'Position',[300,50,100,25]); htext = uicontrol('Style','text','String','Select Data',... 'Position',[325,90,60,15]); 3-Add the axes to the GUI by adding this statement to the code file. Set theUnitsproperty to pixels so that it has the same units as the other components. ha = axes('Units','pixels','Position',[50,60,200,185]);
  • 21. 4-Align all components except the axes along their centers with the following statement. Add it to the code file following all the component definitions. align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None'); 5-Make your GUI visible by adding this command following thealign command. %Make the GUI visible. set(f,'Visible','on') 6-This is what your code file should now look like:
  • 22. 6-This is what your code file should now look like: function simple_gui2 % SIMPLE_GUI2 Select a data set from the pop-up menu, then % click one of the plot-type push buttons. Clicking the button % plots the selected data in the axes. % Create and then hide the GUI as it is being constructed. f = figure('Visible','off','Position',[360,500,450,285]); % Construct the components. hsurf = uicontrol('Style','pushbutton','String','Surf',... 'Position',[315,220,70,25]); hmesh = uicontrol('Style','pushbutton','String','Mesh',... 'Position',[315,180,70,25]); hcontour = uicontrol('Style','pushbutton',... 'String','Countour',... 'Position',[315,135,70,25]); htext = uicontrol('Style','text','String','Select Data',... 'Position',[325,90,60,15]); hpopup = uicontrol('Style','popupmenu',...
  • 23. % Construct the components. hsurf = uicontrol('Style','pushbutton','String','Surf',... 'Position',[315,220,70,25]); hmesh = uicontrol('Style','pushbutton','String','Mesh',... 'Position',[315,180,70,25]); hcontour = uicontrol('Style','pushbutton',... 'String','Countour',... 'Position',[315,135,70,25]); htext = uicontrol('Style','text','String','Select Data',... 'Position',[325,90,60,15]); hpopup = uicontrol('Style','popupmenu',... 'String',{'Peaks','Membrane','Sinc'},... 'Position',[300,50,100,25]); ha = axes('Units','Pixels','Position',[50,60,200,185]); align([hsurf,hmesh,hcontour,htext,hpopup],'Center','None'); %Make the GUI visible. set(f,'Visible','on') end