Introduction to Matlab & Data Analysis

Slides:



Advertisements
Similar presentations
Introduction to Visual Basic.NET Uploaded By: M.Sheraz anjum.
Advertisements

DATA RETRIEVAL AND GUI CREATION DAVID COOPER SUMMER 2014.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
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.
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.
Matlab GUIs Making Matlab Interactive. Today’s topics What is a GUI? How does a GUI work? Where do you begin? Ways to build MATLAB GUIs.
1 Introduction to Human Computer Interaction  Livecode Overview  Based on Livecode User Guide from RunRev Ltd. (2010) 
Access Tutorial 10 Automating Tasks with Macros
Chapter 9 Introduction to ActionScript 3.0. Chapter 9 Lessons 1.Understand ActionScript Work with instances of movie clip symbols 3.Use code snippets.
Form Handling, Validation and Functions. Form Handling Forms are a graphical user interfaces (GUIs) that enables the interaction between users and servers.
Digital Image Processing Lecture3: Introduction to MATLAB.
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.
McGraw-Hill/Irwin © 2004 by The McGraw-Hill Companies, Inc. All rights reserved. Dynamic Action with Macromedia Dreamweaver MX Barry Sosinsky Valda Hilley.
Introduction to Graphical User Interfaces. Objectives * Students should understand what a procedural program is. * Students should understand what an.
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.
CS 170 – INTRO TO SCIENTIFIC AND ENGINEERING PROGRAMMING.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
IE 411/511: Visual Programming for Industrial Applications
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
Introduction To Windows Operating Systems Manipulating Windows GUI
Automating Database Processing Chapter 6. Chapter Introduction Design and implement user-friendly menu – Called navigation form Macros – Automate repetitive.
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.
© 2005 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. Data Structures for Java William H. Ford William R. Topp Appendix E The EZJava.
 Whether using paper forms or forms on the web, forms are used for gathering information. User enter information into designated areas, or fields. Forms.
Introduction to Matlab’s Graphical User Interface (GUI) Type “guide” “Guide” creates interface on a Figure window and code in an M-file. Some hidden code.
function varargout = MovieJoiner(varargin) % MOVIEJOINER M-file for MovieJoiner.fig % MOVIEJOINER, by itself, creates a new MOVIEJOINER or raises the.
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.
CHAPTER TWO Creating Simple Visual Basic.NET Windows Applications.
CSCE 121: Introduction to Program Design and Concepts, Honors Dr. J. Michael Moore Spring 2015 Set 15: GUIs 1.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Graphic User Interfaces (GUI) GUI provides a way to interact friendly with possibly complex programs. There are two types of GUI: - MDI: multiple document.
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.
Visual C# 2012 How to Program © by Pearson Education, Inc. All Rights Reserved.
Topics Introduction Scene Graphs
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.
Copyright © 2015 Pearson Education, Inc. Publishing as Pearson Addison-Wesley C H A P T E R 13 GUI Programming.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 9 : Introduction to GUI & Revision Edward Cheung Room W311g.
Visual Basic for Application - Microsoft Access 2003 Programming applications using Objects.
XP Tutorial 8 New Perspectives on Microsoft Windows XP 1 Microsoft Windows XP Object Linking and Embedding Tutorial 8.
 2002 Prentice Hall. All rights reserved. 1 Chapter 2 – Introduction to the Visual Studio.NET IDE Outline 2.1Introduction 2.2Visual Studio.NET Integrated.
CS112 Scientific Computation Department of Computer Science Wellesley College Interactive Programs Graphical User Interfaces.
EGR 115 Introduction to Computing for Engineers
EGR 115 Introduction to Computing for Engineers Graphical User Interface Design in MATLAB - Part 2 Monday 24 Nov 2014 EGR 115 Introduction to Computing.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
CS112 Scientific Computation Department of Computer Science Wellesley College Blind to change More on GUIs.
Graphical User Interfaces I The central station is the bubble gum planet with 280 pounds of clay and three head phone lines that come out and orbit the.
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.
Module 2 Part II Introduction To Windows Operating Systems Manipulating Windows GUI Introduction To Windows Operating Systems Manipulating Windows GUI.
Visual Basic.Net. Software to Install Visual Studio 2005 Professional Edition (Requires Windows XP Pro) MSDN Library for Visual Studio 2005 Available.
PATTERN RECOGNITION LAB 8 TA : Nouf Al-Harbi::
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.
Topics Graphical User Interfaces Using the tkinter Module
Graphical User Interface in MATLAB
Introduction to Event-Driven Programming
Lecture 25.
More on Graphical User Interfaces
CIS16 Application Development Programming with Visual Basic
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

Introduction to Matlab & Data Analysis Tutorials 12: Graphical User Interface (GUI) Please change directory to directory E:\Matlab (cd E:\Matlab;) From the course website (http://www.weizmann.ac.il/feinberg/courses/EranEden/course_outline.htm) Download: t12.zip Eilon Sharon, Weizmann 2008 ©

Content GUI definition Predefined dialog boxes. GUI terms Using GUIDE to create a GUI

GUI - Definition UI (user interface): The point of contact or method of interaction between a person and a computer or computer program. The UI defines the “look and feel” of the application Windows 1.0

GUI - Definition (Matlab help) A graphical user interface (GUI) is a graphical display that contains devices, or components, that enable a user to perform interactive tasks. To perform these tasks, the user of the GUI does not have to create a script or type commands at the command line. Often, the user does not have to know the details of the task at hand.

Matlab Can Use Operating System Predefined Dialog Boxes For Various Tasks Filter - can contain * Example: [fname, dirpath] = uigetfile('*.m', 'Select a M-file') Title

Useful Dialog Boxes - Examples % Input Boxes: [fname, dirpath] = uigetfile('*.m‘,'Select a M-file') [fname, dirpath] = uiputfile('*.mat') c = uisetcolor([0.5 0 0.5],'My Select Color') fc = uisetfont('My Set Font') % Dialog boxes (Dialog == dlg) msgbox('message box'); errordlg('This is an error Message'); helpdlg('Help:This is a help dialog box'); [selection,ok] = listdlg('ListString',{'a','b','c'}) Try some of these examples

Eilon Sharon, Weizmann 2008 © Creating a GUI 40 GUI examples: http://www.mathworks.com/matlabcentral/fileexchange/24861-41-complete-gui-examples Eilon Sharon, Weizmann 2008 ©

You Can Either Create a GUI Programmatically or Use GUIDE Video Example: http://blogs.mathworks.com/pick/2007/12/28/matlab-basics-guis-without-guide/ Use GUIDE to create a GUI Graphical User Interface Development Environment Use the GUIDE!

The GUI (figure) Contains Components The GUI contains components. Types of components: Buttons: Push button Toggle button Radio Button Check box Lists: Pop up menu List box Button Group Panel Slider Axes

GUI Work in Event Driven Programming Component Each component of the GUI is associated with one or more callback functions The GUI programmer writes the callback functions: The callback function execution is triggered by a particular user action (=event) such as: A button push A mouse click A selection of a menu item cursor passing over a component % --- Executes on button press in pushbutton1. function pushbutton1_Callback(hObject, eventdata, handles) Callback function

Creating a GUI using GUIDE Activate GUIDE, two options: >> guide Press the icon: Choose the Blank GUI option Add components using Drag-and-Drop

First Example – A GUI with Exit button Drag and Drop a “push button”. Double Click on the button to open the “Inspector”. The inspector lets you edit the properties of each component

The Tag Property Is Used as an Identifier of the Component Set the String property to “Exit” Set the Tag property to “exitButton” The Tag property: Sets the name of the automatically generated callback functions Sets the name of the component handle

The GUI Object Contain The GUI Components Objects The GUI object contains the components objects The objects are stored in a hierarchical manner We can browse through the objects using the object browser: The GUI object is of type figure The GUI (figure) is the parent of the push button (uicontrol) The push button is a component of type “uicontrol” Tag

First Run of the GUI Generates the GUI Figure and a M-file At the first run GUIDE generates: A Figure file – hold the GUI figure. A M-file – contains: The GUI main function. Running this function will create and run the GUI The callback functions Lets Run the GUI Save the file as “gui_example1”

The Callback Functions Define the Respond to the Events Our code is now active and we can run it by typing in the command line: >> gui_example1 We now need to add to the automatically generated code the implementation of the callback functions In GUIDE - Right click on the component View callback -> callback % --- Executes on button press in exitButton. function exitButton_Callback(hObject, eventdata, handles) % hObject handle to exitButton (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA)

Adding our Respond to the Click Inside the Callback Function % --- Executes on button press in exitButton. function exitButton_Callback(hObject, eventdata, handles) % hObject handle to exitButton (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close(); In response to a click on the Exit button we will close the GUI (figure) Notice that the function name contains the tag of the component: exitButton_Callback

The input arguments of the Callback functions are: The Callback Input Arguments Contain Information About the Event, Application Shared Data and Components Handles The input arguments of the Callback functions are: hObject – handle of the called object: The object contains information about the call (event). We retrieve the data using the get function, example: get(hObject,'String') eventdata – reserved - to be defined in a future version of MATLAB… handles - structure with handles and user data Handles is used to pass data between functions!

To Learn About the Callback Functions Input Lets Add Components to Our GUI Add an axes component Make sure the tag is “axes1” Add a push button Set String to “Surf” Set tag to “surf” Add a pop up menu Set tag to “dataSelection” Set string to “peaks membrane” Extra - Add a static text Set string to “Select Data” (you can also change font to 14) Play with the color and font properties

Our GUI Maintains Data Inside The Handles Structure and Pass It Between Functions Goal: Our GUI will choose between two types of data – Peaks Membrane A press on the Surf button will draw the selected data in the axes Implementation: The selected data will be save as handles.cur_data Surf will draw the cur_data

Our GUI Maintains Data Inside The Handles Structure and Pass It Between Functions In the M-file go to: function gui_example_OpeningFcn(hObject, eventdata, handles, varargin) Add: % Choose default command line output for gui_example handles.output = hObject; handles.peaks = peaks(35); handles.membrane = membrane; handles.cur_data = handles.peaks; % Update handles structure guidata(hObject, handles); The new code guidata – Finds the parent GUI of the hObject (component). Sets handles as a field of the GUI structure (stores handles in the GUI)

The guidata Function – Stores or Retrieves GUI Data guidata(object_handle,data) data = guidata(object_handle) hObject handles The guidata function knows also to retrieve data, but we won’t use this option since GUIDE automatically generated code does this for us Remember: always after you update the handles call: guidata(hObject, handles);

Updating the Current Data at the Data Selection Callback % --- Executes on selection change in dataSelection. function dataSelection_Callback(hObject, eventdata, handles) % Hints: contents = get(hObject,'String') returns dataSelection contents as cell array % contents{get(hObject,'Value')} returns selected item from dataSelection contents = get(hObject,'String'); data_str = contents{get(hObject,'Value')}; switch data_str case 'peaks' handles.cur_data = handles.peaks; case 'membrane' handles.cur_data = handles.membrane; otherwise errordlg('unknown data selected'); end guidata(hObject, handles); Retrieving event data from the called object Remember to use guidata!

Use the Axes Handle to Draw the Plot in Response to a Press on the Surf Button % --- Executes on button press in surf. function surf_Callback(hObject, eventdata, … handles) surf(handles.axes1,handles.cur_data); The axes handle The current data

Our GUI is Now Fully Functional! Run it: >> gui_example

Steps of Computing a GUI Draw the GUI on a piece of paper Create the GUI using GUIDE Create the code of the GUI (callback functions) DEBUG the GUI by using it in various scenarios

Adding a Menu Add a menu: Lets Add the menu Help Update the callback: (GUIDE) Tools ->Menu editor Lets Add the menu Help Inside Help add sub-menu about Change its tag to about Update the callback: function about_Callback(hObject, eventdata, handles) msgbox('A GUI Example. Tutorial 12', 'About');

Exercise Add a push button “Contour” More advance: When push the button will draw contour plot Put both the contour and the surf button inside a panel More advance: Add a button that saves the current GUI as a jpg. Make the selection of the data, redraw the plot using the selected data and the last selected plot type

Resources GUI tips GUIDE Demo http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=5439&ref=rssfeed&id=mostDownloadedFiles GUIDE Demo http://www.mathworks.com/support/2007a/matlab/7.4/demos/CreatingaGUIwithGUIDE_viewlet_swf.html http://blogs.mathworks.com/pick/2007/12/28/matlab-basics-guis-without-guide/

Summary We have made a very long way: You have all the necessary tools Matlab syntax Array manipulation, Cells, Structures Programming: Functions Writing efficient code Files & strings manipulation Data analysis GUI You have all the necessary tools Enjoy using Matlab Thanks!