Presentation is loading. Please wait.

Presentation is loading. Please wait.

Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy

Similar presentations


Presentation on theme: "Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy"— Presentation transcript:

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

2 Department of Mechanical Engineering, LSUSession VII Last Session….  Introduction to Simulink  Solving simple problems using Simulink

3 Department of Mechanical Engineering, LSUSession VII Session VII Outline….  Introduction to GUI using MATLAB  Creating a GUI using MATLAB

4 Department of Mechanical Engineering, LSUSession 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.

5 Department of Mechanical Engineering, LSUSession 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.

6 Department of Mechanical Engineering, LSUSession 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.

7 Department of Mechanical Engineering, LSUSession VII Blank GUI…. The blank GUI template displayed in the Layout Editor is shown in the following figure.

8 Department of Mechanical Engineering, LSUSession VII UI control objects…. Push Buttons Toggle Buttons Check Boxes Radio Buttons Edit Text Static Text Sliders Frames List Boxes Popup Menus

9 Department of Mechanical Engineering, LSUSession 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

10 Department of Mechanical Engineering, LSUSession 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

11 Department of Mechanical Engineering, LSUSession 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.

12 Department of Mechanical Engineering, LSUSession 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

13 Department of Mechanical Engineering, LSUSession 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.

14 Department of Mechanical Engineering, LSUSession 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.

15 Department of Mechanical Engineering, LSUSession 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

16 Department of Mechanical Engineering, LSUSession 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…

17 Department of Mechanical Engineering, LSUSession 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….

18 Department of Mechanical Engineering, LSUSession VII List Box Example…..

19 Department of Mechanical Engineering, LSUSession 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

20 Department of Mechanical Engineering, LSUSession VII Implementation of GUI…. Use GUIDE to lay out the components interactively Generate two files that save and launch the GUI

21 Department of Mechanical Engineering, LSUSession VII Example : Creating a GUI…. This example will be done in class.

22 Department of Mechanical Engineering, LSUSession 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….

23 Department of Mechanical Engineering, LSUSession VII Thank You


Download ppt "Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy"

Similar presentations


Ads by Google