Graphical User Interface in MATLAB

Slides:



Advertisements
Similar presentations
Using Macros and Visual Basic for Applications (VBA) with Excel
Advertisements

© by Pearson Education, Inc. All Rights Reserved.
Visual Basic 2010 How to Program. © by Pearson Education, Inc. All Rights Reserved.2.
Visual Basic 2010 How to Program Reference: Instructor: Maysoon Bin Duwais slides Visual Basic 2010 how to program by Deitel © by Pearson Education,
A graphical user interface (GUI) is a pictorial interface to a program. A good GUI can make programs easier to use by providing them with a consistent.
Guide to Oracle10G1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros
1 How to create GUI's in MatLAB Rigo Dicochea. 2 Introduction Graphical User Interface (GUI) MatLab provides Graphical User Interface Development Environment(GUIDE)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
Automating Tasks With Macros. 2 Design a switchboard and dialog box for a graphical user interface Database developers interact directly with Access.
Introduction To Form Builder
1 Introduction to the Visual Studio.NET IDE Powerpoint slides modified from Deitel & Deitel.
Access Tutorial 10 Automating Tasks with Macros
Visual Basic 2008 Express Edition The IDE. Visual Basic 2008 Express The Start Page Recent Projects Open an existing project Create a New Project.
Programming a GUI Hanan sedaghat pisheh. For calling GUI, we need a function with no inputs or outputs First We create a m.file m file has the same name.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. >> sphere(100)
Introduction to the Graphical User Interface (GUI) in MATLAB
Matlab GUIs GUIDE.
IE 411/511: Visual Programming for Industrial Applications
Introduction to Matlab & Data Analysis
Java Software Solutions Lewis and Loftus Chapter 10 1 Copyright 1997 by John Lewis and William Loftus. All rights reserved. Graphical User Interfaces --
GUI development with Matlab: GUI Front Panel Components 1 GUI front panel components In this section, we will look at -GUI front panel components -Programming.
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved. 1 3 Welcome Application Introduction to Visual Programming.
Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Chapter 2 – Introduction to the Visual Studio .NET IDE
1 Creating Windows GUIs with Visual Studio. 2 Creating the Project New Project Visual C++ Projects Windows Forms Application Give the Project a Name and.
Introduction to Matlab & Data Analysis 2015 In this tutorial we will: Build a practical application using GUIDE Learn more about graphical user interface.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Programming Logic & Design Second Edition by Tony Gaddis.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
XP New Perspectives on Microsoft Office Access 2003 Tutorial 10 1 Microsoft Office Access 2003 Tutorial 10 – Automating Tasks With Macros.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
EGR 115 Introduction to Computing for Engineers
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
More Matlab Graphics and GUI Graphics subplots some useful commands 3D graphics GUI GUI controls The callback property Other essential properties.
 2002 Prentice Hall. All rights reserved. 1 Introduction to the Visual Studio.NET IDE Outline Introduction Visual Studio.NET Integrated Development Environment.
DB Implementation: MS Access Forms. MS Access Forms: Purpose Data entry, editing, & viewing data in Tables Forms are user-friendlier to end-users than.
Dive Into® Visual Basic 2010 Express
Multiple Forms and Menus
Visual Basic.NET Windows Programming
Working with Data Blocks and Frames
Chapter 2: The Visual Studio .NET Development Environment
Working in the Forms Developer Environment
Topics Graphical User Interfaces Using the tkinter Module
Chapter Topics 15.1 Graphical User Interfaces
Chapter 8: Writing Graphical User Interfaces
Chapter 2 – Introduction to the Visual Studio .NET IDE
3.01 Apply Controls Associated With Visual Studio Form
Graphical User Interface Concepts: Part I
1. Introduction to Visual Basic
Introduction to the Visual C# 2005 Express Edition IDE
Chap 7. Building Java Graphical User Interfaces
More on Graphical User Interfaces
DB Implementation: MS Access Forms
Graphical User Interfaces -- Introduction
Microsoft Windows 2000 Professional
Chapter 2 – Introduction to the Visual Studio .NET IDE
DB Implementation: MS Access Forms
Topics Graphical User Interfaces Using the tkinter Module
Chapter 15: GUI Applications & Event-Driven Programming
Creating Additional Input Items
Electrical and Computer Engineering Department SUNY – New Paltz
TA: Nouf Al-Harbi NoufNaief.net :::
Presentation transcript:

Graphical User Interface in MATLAB Credits: Angeline Beulah. V, SSN College of Engineering, Chennai

GUI GUI-Graphical User Interface Provide point-and-click control of software applications. Eliminate the need to learn a language or type commands in order to run the applications.

Topics to be Covered How to create GUIs with MATLAB Laying out the components Programming them to do specific things in response to user actions Saving and launching the GUI Will not go into detail on MATLAB scripts Will not attempt to cover the "art" of good user interface design

Two ways to open the GUI window Click NewGraphical User Interface.(ver R2014a) Type guide on the command window. GUIDE (Graphical User Interface Development Environment)

GUIDE (Graphical User Interface Development Environment) GUIDE is primarily a set of layout tools GUIDE also generates an M-file that contains code to handle the initialization and launching of the GUI This M-file also provides a framework for the implementation of the callbacks - the functions that execute when users activate a component in the GUI.

GUI window layout

GUIDE - Primarily a Set of Layout Tools Control Panel - add and arrange objects in the figure window Alignment Tool - align objects Property Editor - inspect and set property values Object Browser - observe a hierarchical list of the Handle Graphics objects Menu Editor - create window menus and context menus

Components Palette The L.H.S. of the Guide window contains the components palette. Your layout-design task will involve dragging and dropping the GUI control components from the palette onto the layout area. File-> Preferences option of the GUIDE window will allow you to display the names of the items in the components

uicontrol objects Push Buttons Toggle Buttons Check Boxes Radio Buttons Edit Text Static Text Sliders Frames List Boxes Popup Menus

Push Buttons Push buttons generate an action when pressed (e.g., an OK button may close a dialog box and apply settings) When you click down on a push button, it appears depressed; when you release the mouse, the button's appearance returns to its non-depressed state; and its callback executes on the button up event

Toggle Buttons Toggle buttons generate an action and indicate a binary state (e.g., on or off) The callback routine needs to query the toggle button to determine what state it is in You can do this with a statement that uses the current callback object's handle (gcbo) get(gcbo,'Value') MATLAB sets the Value property to 1 when depressed and 0 when not depressed

Check Boxes Generate an action when clicked and indicate their state as checked or not checked Useful when providing the user with a number of independent choices that set a mode The Value property indicates the state of the check box by taking on the value 1 or 0 Value = 1, box is checked. Value = 0, box is not checked.

Radio Boxes Similar to check boxes, but are intended to be mutually exclusive within a group of related radio buttons (i.e., only one button is in a selected state at any given time) To make radio buttons mutually exclusive within a group, the callback for each radio button must set the Value property to 0 on all other radio buttons in the group

Edit Text Fields that enable users to enter or modify text strings Use edit text when you want text as input The String property contains the text entered by the user.

Static Text Displays lines of text Typically used to label other controls, provide directions to the user, or indicate values associated with a slider Users cannot change static text interactively and there is no way to invoke the callback routine associated with it.

Sliders Accept numeric input within a specific range by enabling the user to move a sliding bar The location of the bar indicates a numeric value Can set Current Value, Range, and Step size

List Boxes Display a list of items (defined using the String property) and enable users to select one or more items By default, the first item in the list is highlighted when the list box is first displayed If you do not want any item highlighted, then set the Value property to empty, []

Popup Menus Open to display a list of choices (defined using the String property) when users press the arrow When not open, a popup menu displays the current choice, which is determined by the index contained in the Value property The first item in the list has an index of 1 You can query the Value property in the callback routine to determine which choice the user made Can be used in place of Radio Buttons

Commands Example:1 x=0:0.1:3*pi y=sin(x) area(x,y) [x,y]=ginput(1) %plot(x,y) Output: >> first x = 4.7541 y = 0.1257

Example:2 bar([2,7,4.5,6]) colormap cool

Example:3 T=0:0. 1:2. pi; for j=1:12 plot(5. cos(j. pi/6)+cos(T),5 Example:3 T=0:0.1:2*pi; for j=1:12 plot(5*cos(j*pi/6)+cos(T),5*sin(j*pi/6)+sin(T)); axis([-6 6 -6 6]); M(j)=getframe; end movie(M)

Example:4 [x,y]=meshgrid(-2:0. 2:2,-2:0. 2:2); contour(x,y,x. ^2-y Example:4 [x,y]=meshgrid(-2:0.2:2,-2:0.2:2); contour(x,y,x.^2-y.^2) z=x*y; surf(x,y) %contourf(x,y,x.^2-y.^2) %[x,y]=ginput(4)

The Process of Implementing a GUI Involves Two Basic Tasks: Laying out the GUI components MATLAB implements GUIs as figure windows containing various styles of uicontrol (User Interface) objects. Programming the GUI components Must program each object to perform the intended action when activated by the user of the GUI.

Example:1 %to display ‘HAI’ Steps: Enter ‘guide’ on the command window. A window created as:

Click Blank GUI –> OK Select which type of uicontrol component from the component palette needed and place it in the GUI window. For this example we select the pushbutton

Change the name of the pushbutton by right clicking the pushbutton. Save the GUI window.

When a GUI is saved then it is saved in two forms: 1. in .fig 2. in .m

By pushing the button , the word HAI has to be displayed in command window. So we add ‘disp HAI’ in the callback of the pushbutton. Click save and Run the Program. when button pushed we get >> hai HAI in the command window.

Callbacks Routine that executes whenever you activate the uicontrol object. Define this routine as a string that is a valid MATLAB expression or the name of an M-file. The expression executes in the MATLAB workspace.

FIG-files Binary files created as a result of saving a figure Contains a serialized figure object A complete description of the figure object and all of its children All of the objects property values are set to the values they were saved with when the figure is recreated

M-files MATLAB generates the application M-file to provide a framework for the program that controls the GUI All code, including the callbacks, is contained in the application M-file Each callback is implemented as a sub-function in the M-file

Example:2 % to create an adder function input1_editText_Callback(hObject, eventdata, handles) input = str2num(get(hObject,'String')); if (isempty(input)) set(hObject,'String','0') end guidata(hObject, handles);

function input2_editText_Callback(hObject, eventdata, handles) input = str2num(get(hObject,'String')); if (isempty(input)) set(hObject,'String','0') end guidata(hObject, handles);

function add_pushbutton_Callback(hObject, eventdata, handles) a = get(handles.input1_editText,'String'); b = get(handles.input2_editText,'String'); total = str2num(a) + str2num(b); c = num2str(total); set(handles.answer_staticText,'String',c); guidata(hObject, handles);

GUI window:Output

Matlab Graphics Objects Output Example:1 >> hf=figure; ha=axes; x=-10:0.1:10; h=line(x,exp(-x.^2)); get(hf,'Type') get(ha,'Parent')=hf; P=get(ha,'Position'); set(ha,'Position',[P(1) P(2)+P(4)/4 P(3) P(4)/2]); set(hf,'color',[0 0 0 ]) set(h,'color',[ 1 0 0],'Linewidth',5) hf1=figure; ha1=axes('Parent',hf1); set(h,'Parent',ha1)

Example:2 hf=figure('MenuBar','none') hTb=uitoolbar hPT=uipushtool(hTb,'CData',zeros(8,8,3)) hTT=uitoggletool(hTb,'CData',zeros(8,8,3),'Separator','on') hM=uimenu(hf,'Label','Test') ha=axes('Position',[0.45 0.1 0.5 0.8]) hL(1)=plot([0:10],rand(11,1)) hL(2)=line([0:10],sin(pi*[0:10]/10),'Color',[1 0 0]) hL(3)=annotation('line',[0.75 0.75],[0 1],'Color',[1 0 0]) ha1=get(hL(3),'Parent') hGo(1)=rectangle('Position',[4,1.5,1,0.2],'FaceColor',[0 0.5 0]) hGo(2)=line([4 5],[1.5 1.7],'Color',[1 0 0]) hG=hggroup set(hGo,'HitTest','off','Parent',hG)

PanProp.Parent=hf PanProp.Position=[0.05 0.1 0.3 0.8] PanProp.Title='UI panel example' PanProp.BackgroundColor=get(hf,'Color') hPan=uipanel(PanProp) UIPr.Units='normalized' UIPr.Parent=hPan UIPr.Position=[0.1 0.05 0.8 0.07] UIPr.Style='pushbutton' hUI(1)=uicontrol(UIPr,'String','Test Button') UIPr.Style='listbox' UIPr.Backgroundcolor=[1 1 1] UIPr.Position=[0.1 0.17 0.8 0.75] hUI(2)=uicontrol(UIPr,'String',fieldnames(get(hf)))

Output

Thank You