Top Banner
Department of Mechanical Engineering, LSU Session VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email: [email protected] Dept of Mechanical Engineering LSU
23

Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:[email protected]@lsu.edu.

Dec 29, 2015

Download

Documents

Beryl Oliver
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

MATLAB Tutorials

Session VIIIGraphical User Interface using MATLAB

Rajeev MadazhyEmail: [email protected]

Dept of Mechanical Engineering

LSU

Page 2: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Last Session….

Introduction to Simulink

Solving simple problems using Simulink

Page 3: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Session VII Outline….

Introduction to GUI using MATLAB

Creating a GUI using MATLAB

Page 4: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

GUI…..

A graphical user interface (GUI) is a user interface built with graphical objects

— the components of the GUI — such as buttons, text fields, sliders, and

menus. If the GUI is designed well-designed, it should be intuitively obvious to

the user how its components function.

Page 5: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Creating GUI’s with GUIDE…..

MATLAB implements GUIs as figure windows containing various uicontrol

objects. You must program each object to perform the action you intend it to do

when a user activates the component. In addition, you must be able to save and

run your GUI. All of these tasks are simplified by GUIDE, the MATLAB

graphical user interface development environment.

Page 6: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Using GUIDE….

GUIDE provides several templates, which simple examples that you can modify to create your own GUIs. The templates are fully functional GUIs: their callbacks are already programmed. You can view the code for these callbacks to see how they work, and then modify the callbacks for your own purposes.

You can access the templates in two ways:

•Start GUIDE by entering guide at the MATLAB prompt.

•If GUIDE is already open, select New from the File menu in the Layout Editor.

Page 7: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Blank GUI….

The blank GUI template displayed in the Layout Editor is shown in the following figure.

Page 8: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

UI control objects….

•Push Buttons•Toggle Buttons•Check Boxes•Radio Buttons•Edit Text

•Static Text•Sliders •Frames •List Boxes•Popup Menus

Page 9: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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

Page 10: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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

Page 11: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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.

Page 12: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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

Page 13: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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.

Page 14: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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.

Page 15: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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

Page 16: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

•Boxes that enclose regions of a figure window •Can make a user interface easier to understand by visually grouping related controls •Have no callback routines associated with them and only uicontrols can appear within frames (axes cannot)

Frames…

Page 17: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

•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, []

List Boxes….

Page 18: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

List Box Example…..

Page 19: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

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

Page 20: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Implementation of GUI….

•Use GUIDE to lay out the components interactively•Generate two files that save and launch the GUI

Page 21: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Example : Creating a GUI….

This example will be done in class.

Page 22: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

This completes the MATLAB Tutorial.

Sessions 1 to 7 covered almost all areas of applications of MATLAB.

Specialized areas of MATLAB are using the toolboxes. These are a collection of m-files that are specific to the area of application.

Looking back….

Page 23: Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu.

Department of Mechanical Engineering, LSU Session VII

Thank You