Creating Graphical User Interfaces in Matlab

introduction to matlab n.w
1 / 19
Embed
Share

Learn about GUI development in Matlab using GUIDE (GUI Development Environment), including designing GUIs, components, figures, callbacks, and the overall design process. Explore practical examples like plotting the sum of two functions entered in a textbox.

  • Matlab GUI
  • GUI Development
  • User Interfaces
  • Matlab Programming
  • Guide

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Introduction to Matlab Module #10 Creating Graphical User Interfaces Topics 1. Overview of GUI Development using GUIDE (GUI Development Environment) 2. Designing a GUI Reading Assignments 1. Intro to GUI Programming in Matlab by UAE University (on website) Practice Problems 1. Make a GUI that will plot the sum of two functions entered in a textbox Module #10 Page 1 Introduction to Matlab

  2. 1) Overview of GUI Development with GUIDE GUI Overview - There are three elements to a Matlab GUI These are the graphical items in the GUI such as buttons, text boxes radio buttons, menus, etc These are how the user interracts with the GUI and enters information 1) Components Components exist within a figure. The figure is a box that can hold one or more components. These can be thought of as windows or subwindows. 2) Figures This is the code that is performed when a user clicks on a component. The callback is the operation that will be performed for each component that the user may access. 3) Callbacks Module #10 Page 2 Introduction to Matlab

  3. 1) Overview of GUI Development with GUIDE GUIDE - GUIDE is the tool that allows you to graphically create and layout a GUI. - When you layout your GUI and save it within GUIDE, two files are created. A fig file which will launch the GUI when executed and a M-file which contains the code for each callback that will be ran when a component is accessed. - The first time you enter a component in the layout and save it, GUIDE creates a skeleton M-file in which you enter the functionality that you want for each callback. Module #10 Page 3 Introduction to Matlab

  4. 1) Overview of GUI Development with GUIDE Overview of GUI Design Process 1) Decide on the design of the GUI - graphical layout - functionality of each component 2) Use GUIDE to layout the components on a figure 3) Use the Property Inspector within GUIDE to assign a tag to each component. The tag is a unique identifier for each component and will be used to set the individual properties. 4) Save the GUI in GUIDE creating two files - fig file: - M-file: This contains the actual GUI layout This is a skeleton Matlab script that will contain the callback code 5) Write the code to implement the behavior associated with each callback function. Module #10 Page 4 Introduction to Matlab

  5. 2) Designing a GUI Step 1 Deciding on a Design - Let s create a GUI that will plot y = mx + b and the user can enter the parameters (End Time, m, and b) - First, let s sketch the layout we want: End Time Enter End Time m Enter m Plot Window b Enter b Push Button Module #10 Page 5 Introduction to Matlab

  6. 2) Designing a GUI Step 2 Use GUIDE to layout the window - Start GUIDE typing guide at the prompt in Matlab - Select Blank GUI and click OK Module #10 Page 6 Introduction to Matlab

  7. 2) Designing a GUI Step 2 Use GUIDE to layout the window cont - Set the size of the layout window. This will be the default size of the window when the GUI is launched. - This is done by dragging the corners of the gridded square in GUIDE. The gridded rectangle is the GUI window that will be created. Module #10 Page 7 Introduction to Matlab

  8. 2) Designing a GUI Step 2 Use GUIDE to layout the window cont - Enter three Edit Text boxes by clicking on the icons on the left. Once you click the icon, click in the layout window. You can reposition and resize the fields by dragging the corners of the box. - These are where the user will enter the time range and two functions to be added. Module #10 Page 8 Introduction to Matlab

  9. 2) Designing a GUI Step 2 Use GUIDE to layout the window cont - Enter three Static Text boxes using the icons the left. Once you click the icon, click in the layout window. You can reposition and resize the fields by dragging the corners of the box. - Double Click on each Static Text box to launch the Inspector dialog. In this window, edit the string value for each text string to give a description of each box Module #10 Page 9 Introduction to Matlab

  10. 2) Designing a GUI Step 2 Use GUIDE to layout the window cont - Enter a push button using the icons on the left. - Use the Inspector dialog to give the button the text Plot y = mx + b Module #10 Page 10 Introduction to Matlab

  11. 2) Designing a GUI Step 2 Use GUIDE to layout the window cont - Enter an axis using the icons on the left. Module #10 Page 11 Introduction to Matlab

  12. 2) Designing a GUI Step 3 Assign tags using the Property Inspector - Double Click on each component that will need a call back and assign the property for the tab tag suggestions: time_field function_field1 function_field2 pushbutton1 plot1 Module #10 Page 12 Introduction to Matlab

  13. 2) Designing a GUI Step 4 Save the GUI - Click the Save button in GUIDE - give the name sum_gui.fig - This creates two files: sum_gui.fig - contains the window layout information sum_gui.m - contains the code for your callbacks. - Start the GUI by typing the name at the prompt in Matlab >> sum_gui Module #10 Page 13 Introduction to Matlab

  14. 2) Designing a GUI Step 5 Write the code for the callbacks - The GUI at this point does not know what to do when a user accesses the components. - We need to enter code in the sum_gui.m file for each action within the gui. - The skeleton M-file is pre-populated with the names of the component tags Module #10 Page 14 Introduction to Matlab

  15. 2) Designing a GUI Step 5 Write the code for the callbacks - Let s start by reading the end time that the user enters. We need to use the get command to bring in the information and assign it to a variable. The information is brought in as a string so we need to convert it using the str2double command. - Also note that we can visibility of our final time vector to other functions using the global command. Module #10 Page 15 Introduction to Matlab

  16. 2) Designing a GUI Step 5 Write the code for the callbacks - Now let s read in m. We can combine the get and str2double into one line of code Module #10 Page 16 Introduction to Matlab

  17. 2) Designing a GUI Step 5 Write the code for the callbacks - Now let s read in b Module #10 Page 17 Introduction to Matlab

  18. 2) Designing a GUI Step 5 Write the code for the callbacks - Now let s write the plot code. We address the plot1 component using the handle.tagname argument Module #10 Page 18 Introduction to Matlab

  19. 2) Designing a GUI Test your Code Module #10 Page 19 Introduction to Matlab

More Related Content