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.

Slides:



Advertisements
Similar presentations
Prof. Muhammad Saeed Mathematical Modeling and Simulation UsingMATLAB Graphic User Interface (GUI)Basics.
Advertisements

Course Form In the main window (cf. Figure 2), click on Forms, then double-click on Create form by using wizard. Follow the sequence of actions below.
How To Use The Podium Touch Panel. Volume Up Volume Down Volume Mute Microphone On/Off Power Off / Exit The touch panel can operate by touching anywhere.
DATA RETRIEVAL AND GUI CREATION DAVID COOPER SUMMER 2014.
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.
© The McGraw-Hill Companies, 2006 Chapter 18 Advanced graphics programming.
Inventory Throughout this slide show there will be hyperlinks (highlighted in blue) follow the hyperlinks to navigate to the specified Topic or Figure.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Fundamentals of Programming in Visual Basic 3.1 Visual basic Objects Visual Basic programs display a Windows style screen (called a form) with boxes into.
Word Templates- Documents Directly from GP.
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.
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.
Copyright ©: SAMSUNG & Samsung Hope for Youth. All rights reserved Tutorials Software: Building apps Suitable for: Advanced.
Hello World In C++ and Microsoft Visual C++. Directions to begin a project 1. Go to All Programs 2. Open Visual Studio C++ 3. Click on New Project 4.
Using Dreamweaver. Slide 1 Dreamweaver has 2 screens that do different things The Document window where you create your WebPages The Site window where.
Database-Driven Web Sites, Second Edition1 Chapter 8 Processing ASP.NET Web Forms and Working With Server Controls.
by Chris Brown under Prof. Susan Rodger Duke University June 2012
Digital Image Processing Lecture 14: GUI using Matlab
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.
PMS /134/182 HEX 0886B6 PMS /39/80 HEX 5E2750 PMS /168/180 HEX 00A8B4 PMS /190/40 HEX 66CC33 By Adrian Gardener Date 9 July 2012.
Introduction to Visual Basic. Quick Links Windows Application Programming Event-Driven Application Becoming familiar with VB Control Objects Saving and.
Robinson_CIS_285_2005 HTML FORMS CIS 285 Winter_2005 Instructor: Mary Robinson.
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 --
CREATING TEMPLATES CREATING CUSTOM CHARACTERS IMPORTING BATCH DATA SAVING DATA & TEMPLATES CREATING SERIES DATA PRINTING THE DATA.
Creating Buttons – Lesson 51 Creating Buttons Lesson 5.
 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.
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.
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.
1 HTML Forms
Dreamweaver MX. 2 Overview of Templates n Forms enable you to collect data from ______. n A form contains ________ such as text fields, radio buttons,
Chapter 5: More on the Selection Structure Programming with Microsoft Visual Basic 2005, Third Edition.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
How to get started with Excel VBA. We need to enable programming in Excel  the “Developer menu”
A Simple Guide to Using SPSS ( Statistical Package for the Social Sciences) for Windows.
1 HTML Forms
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.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
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.
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.
Microsoft Access Intro Class 9 Report Design.
Creating User Interfaces Chapter 13 CSCI CSCI 1302 – Creating User Interfaces2 Outline Introduction Common Features of Swing GUI Components Buttons.
CS112 Scientific Computation Department of Computer Science Wellesley College Interactive Programs Graphical User Interfaces.
EGR 115 Introduction to Computing for Engineers
T U T O R I A L  2009 Pearson Education, Inc. All rights reserved Student Grades Application Introducing Two-Dimensional Arrays and RadioButton.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
1 HTML forms (cont.)
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
Results Table of contents Table of contents Table of contents Section 1 Table of contentsTable of contents Opening the Results module.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
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.
Integrating Components and Dynamic Text Boxes with the Animated Map– Lesson 101 Integrating Components and Dynamic Text Boxes with the Animated Map Lesson.
Graphical User Interfaces I
Graphical User Interface in MATLAB
3.01 Apply Controls Associated With Visual Studio Form
3.01 Apply Controls Associated With Visual Studio Form
More on Graphical User Interfaces
Introducing Forms.
Simple Windows Applications
Visual C# - GUI and controls - 1
Presentation transcript:

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 the components

GUI development with Matlab: GUI Front Panel Components 2 Classes of GUI components 1.Analog input 2.Discrete input 3.Display output 4.Groups

GUI development with Matlab: GUI Front Panel Components 3 Analog input An analog input component receives user- defined choices that are analog The GUI components in this class are -Edit text -Slider

GUI development with Matlab: GUI Front Panel Components 4 Discrete input A discrete input component receives user- defined choices that are discrete (clear cut choices)

GUI development with Matlab: GUI Front Panel Components 5 Discrete input Discrete input components -Radio button -Checkbox -Popup menu -Listbox -Push button -Toggle button

GUI development with Matlab: GUI Front Panel Components 6 Display output A display output component is used to show the result of the GUI calculation/processing The GUI components in this class are -Axes -Static text They have no Callbacks

GUI development with Matlab: GUI Front Panel Components 7 Groups A groups component is used to put several components together as ‘one package’ GUI components in this class -Panel -Button group

GUI development with Matlab: GUI Front Panel Components 8 Example 1 Create a GUI that says ‘Hello’ when you press a Push button.

GUI development with Matlab: GUI Front Panel Components 9 Example 1 (solution) -Start GUIDE -Drag and drop a Push Button to the front panel

GUI development with Matlab: GUI Front Panel Components 10 Example 1 (solution)

GUI development with Matlab: GUI Front Panel Components 11 Example 1 (solution) -Double click on the Push Button to change its properties (String and Tag)

GUI development with Matlab: GUI Front Panel Components 12 Example 1 (solution) The ‘String’ field is what will be seen by the GUI user. You can change it to e.g. ‘Say Hello’ The ‘Tag’ is the name that Matlab recognizes for this component. It is recommended that you change it to e.g. ‘PB_hello’

GUI development with Matlab: GUI Front Panel Components 13 Example 1 (solution) -You’ve finished designing the front panel. -Now program the Callback (in an mfile).

GUI development with Matlab: GUI Front Panel Components 14 Example 1 (solution) Press this to open the ‘mfile editor’ and program the Callback. PS – be prepared to give it a filename to save

GUI development with Matlab: GUI Front Panel Components 15 Example 1 (solution) -Now look for a function ‘PB_hello_Callback’. The mfile automatically creates a function using the name that you gave the component (PB_hello) and adds ‘Callback’ behind it. -Under the function, write the commands that you want it to execute.

GUI development with Matlab: GUI Front Panel Components 16 Example 1 (solution) This is the command that you have typed

GUI development with Matlab: GUI Front Panel Components 17 Example 1 (solution) -Now you’re ready to go! -Execute the GUI Press to execute

GUI development with Matlab: GUI Front Panel Components 18 Example 1 (solution) -It will appear as a Figure.

GUI development with Matlab: GUI Front Panel Components 19 Example 1 (solution) -The result Displays ‘Hello’ as commanded

GUI development with Matlab: GUI Front Panel Components 20 Example 1 (solution) -The result Displays ‘Hello’ as commanded

GUI development with Matlab: GUI Front Panel Components 21 You have just seen … -How to design the front panel -The use of a Tag and String -How to program a Callback -The process of creating and executing a simple GUI Now we’ll look at the how to program each GUI component, and the syntax

GUI development with Matlab: GUI Front Panel Components 22 Edit Text A component that allows the user to enter text – string or number.

GUI development with Matlab: GUI Front Panel Components 23 >>K=get(hObject,'string'); If you entered ‘abc’ into the Edit Text, then the command above will make K = ‘abc’ Edit Text (Callback) Retrieves the ‘string’ entered by user. This is a standard command. A variable. You can call it anything.

GUI development with Matlab: GUI Front Panel Components 24 At this point, K is a string. If the user enters a number, it will still be a string. To change it to a number, >>K_num=str2double(K); Edit Text (Callback) Another variable that you can call anything.

GUI development with Matlab: GUI Front Panel Components 25 To pass the variable K for processing (to another Callback), type >>handles.K=K; >>guidata(hObject,handles); Edit Text (Callback) Another variable. But must be in the format ‘handles.anyname’ Standard command line used to ‘save’ all handles information.

GUI development with Matlab: GUI Front Panel Components 26 Slider A component that allows the user to select a value from the slider, between the pre-specified minimum and maximum.

GUI development with Matlab: GUI Front Panel Components 27 Slider The maximum and minimum values of the slider can be set in the Property Inspector.

GUI development with Matlab: GUI Front Panel Components 28 >>K=get(hObject,'value'); >>handles.K=K; >>guidata(hObject,handles); Slider (Callback) This is a standard command. A slider will always return a numerical value, that’s why the label ‘value’. Reminder: These commands are used if you want the value of ‘K’ to be passed to other Callbacks for further processing.

GUI development with Matlab: GUI Front Panel Components 29 Radio button A radio button acts as an option to be chosen by the user. The user clicks on the button the make the choice.

GUI development with Matlab: GUI Front Panel Components 30 >>K=get(hObject,'value'); Radio button (Callback) ‘value’ will be equal to 1 if the user selects the radio button. Otherwise it will be 0.

GUI development with Matlab: GUI Front Panel Components 31 Checkbox Identical to the Radiobutton, except in a different form.

GUI development with Matlab: GUI Front Panel Components 32 >>K=get(hObject,'value'); Checkbox (Callback) ‘value’ will be equal to 1 if the user selects the checkbox. Otherwise it will be 0.

GUI development with Matlab: GUI Front Panel Components 33 Pop-up menu A pop-up menu, when clicked, displays a list of options for the user to choose from.

GUI development with Matlab: GUI Front Panel Components 34 Pop-up menu To generate the list of options for the user 1. Press this button in the ‘String’ field 2. And this window will appear

GUI development with Matlab: GUI Front Panel Components 35 Pop-up menu To generate the list of options (cont.) 3. Type in the options, each separated by ‘Enter’

GUI development with Matlab: GUI Front Panel Components 36 >>K=get(hObject,'value'); Pop-up menu (Callback) ‘value’ will indicate the index of the choice made. Example: If the 2 nd choice is made, then ‘value’=2.

GUI development with Matlab: GUI Front Panel Components 37 Listbox Identical to the Pop-up menu, except that the options are already visible without being clicked on. (To see options in Pop-up menu, need to click on it first).

GUI development with Matlab: GUI Front Panel Components 38 Pushbutton A push-button is one that will execute a series of commands when pushed. No specific Callback commands. Just type in the commands you want to execute.

GUI development with Matlab: GUI Front Panel Components 39 Toggle button Gives a state when pressed.

GUI development with Matlab: GUI Front Panel Components 40 >>K=get(hObject,'value'); Toggle button (Callback) ‘value’ will be equal to 1 if the toggle button is pressed. Otherwise it will be 0.

GUI development with Matlab: GUI Front Panel Components 41 Static text Allows you to type text on your GUI. Also allows you to output text depending on the user’s actions.

GUI development with Matlab: GUI Front Panel Components 42 Static text No Callback generated for Static Text. To output ‘user-dependent’ text, type >>set(handles.StaticText,'string',‘Your text’); Standard command The Tag of the Static Text (you assigned). Format is handles.Tag Text to output

GUI development with Matlab: GUI Front Panel Components 43 Axes Allows the user to plot graphs

GUI development with Matlab: GUI Front Panel Components 44 Axes No Callback generated for Axes. To plot a graph, type >>axes(handles.axes1); You have now referred to a specific graph. Now type whatever plotting commands you wish to. Standard command The Tag of the axes (you assigned). Format is handles.Tag

GUI development with Matlab: GUI Front Panel Components 45 Extra: Retrieving data You can also retrieve data from another component without that Callback sending out the data (see example on Edit Text and Slider) e.g. – you want to retrieve the data (choice) from a Listbox

GUI development with Matlab: GUI Front Panel Components 46 Extra: Retrieving data In the Listbox Callback >>K=get(hObject,'value'); >>K=handles.K; >>guidata(hObject,handles); Then in the Pushbutton Callback >>K=handles.K; >>guidata(hObject,handles); To send data out Retrieve data

GUI development with Matlab: GUI Front Panel Components 47 Extra: Retrieving data You don’t have to do that! There is an alternative! In the Pushbutton Callback >> get(handles.tag, ‘value’); The tag of the Listbox The value returned by the Listbox

GUI development with Matlab: GUI Front Panel Components 48 Extra: Retrieving data If the component is not activated, the default returned value will be 1

GUI development with Matlab: GUI Front Panel Components 49 Example 2 Create a GUI that plots the function entered by the user when the user pushes a Push Button -The user can enter the upper and lower bounds of the x-axis, and the resolution. -A pop-up menu enables the user to choose the graph colour – blue (default), red, green or yellow.

GUI development with Matlab: GUI Front Panel Components 50 Example 2 (solution)

GUI development with Matlab: GUI Front Panel Components 51 Example 2 (solution) Now let’s look at how to program the Callbacks It can all be done within the Push Button Callback

GUI development with Matlab: GUI Front Panel Components 52 Example 2 (solution) >>lowbound=get(handles.Edtxt_lowbound,'string'); >>lowbound_no=str2double(lowbound); Tag of the Edit Text box which enters the lower bound of the x-axis Retrieve data Converts the string to a numeric value

GUI development with Matlab: GUI Front Panel Components 53 Example 2 (solution) Do the same for the -Upper bound -Interval -Function entered by the user (but no need to convert to number)

GUI development with Matlab: GUI Front Panel Components 54 Example 2 (solution) >>for i=1:((upbound_no-lowbound_no)/interval_no)+1; >> u(i)=lowbound_no+interval_no*(i-1); >> x=u(i); >> y(i)=eval(graph_func); >>end >>hline=plot(u,y); Data retrieved by the graph function Giving the plotted line a name, to set properties later

GUI development with Matlab: GUI Front Panel Components 55 Example 2 (solution) >>1+1 >>‘1+1’ >> eval(‘1+1’) >> x=3; eval(‘x+4’) This will give a number 2 This will still give a string ‘1+1’ This will give a number 7s

GUI development with Matlab: GUI Front Panel Components 56 Example 2 (solution) >>linecolour=get(handles.Popup_colour,'value'); >>linestyle=get(handles.Listbox_style,'value'); Retrieve data on what user specified with regard to line colour and style

GUI development with Matlab: GUI Front Panel Components 57 Example 2 (solution) >>switch linecolour >> case 1 >> set(hline,'color','b'); >> case 2 >> set(hline,'color','r'); >> case 3 >> set(hline,'color','y'); >>end This is why we gave the line a name earlier A property field (standard command) of the line

GUI development with Matlab: GUI Front Panel Components 58 Example 2 (solution) >>switch linestyle >> case 1 >> set(hline,'linestyle','-'); >> case 2 >> set(hline,'linestyle',':'); >> case 3 >> set(hline,'linestyle','--'); >>end

GUI development with Matlab: GUI Front Panel Components 59 Example 2 (solution) >>grid_on=get(handles.Radio_grid,'value'); >>if grid_on==1 >> grid on; >>else >> grid off; >>end If the Radio button is clicked, it will return a value of 1

GUI development with Matlab: GUI Front Panel Components 60 Example 2 (solution) Now, test the GUI -Enter the function in terms of ‘x’ -Enter the lower bound, upper bound, and interval -Press the Plot It button -Make other modifications in terms of line colour, style and grid

GUI development with Matlab: GUI Front Panel Components 61 Example 3 Create a GUI with the following features -Calculates the volume of a cuboid when the user enters the height, width and depth -Outputs the result in a Static Text box

GUI development with Matlab: GUI Front Panel Components 62 Example 3 (solution) Tag – Edtxt_height Tag – Edtxt_width Tag – Edtxt_depth Tag – Pb_calculate Tag – Sttxt_result

GUI development with Matlab: GUI Front Panel Components 63 Example 3 (solution) In the Edtxt_height Callback >>height=get(hObject,'String'); >>height_num=str2double(height); >>handles.height_num=height_num; >>guidata(hObject, handles);

GUI development with Matlab: GUI Front Panel Components 64 Example 3 (solution) In the Edtxt_width Callback >>width=get(hObject,'String'); >>width_num=str2double(width); >>handles.width_num=width_num; >>guidata(hObject, handles);

GUI development with Matlab: GUI Front Panel Components 65 Example 3 (solution) In the Edtxt_depth Callback >>depth=get(hObject,'String'); >>depth_num=str2double(depth); >>handles.depth_num=depth_num; >>guidata(hObject, handles);

GUI development with Matlab: GUI Front Panel Components 66 Example 3 (solution) In the PB_calculate Callback >>depth_num=handles.depth_num; >>width_num=handles.width_num; >>height_num=handles.height_num; >>result=depth_num*width_num*height_num >>result_str=num2str(result) >>set(handles.Sttxt_result,'string',result_str) Convert the number to a string first before sending out to the Static Text

GUI development with Matlab: GUI Front Panel Components 67 Conclusion Looked at the GUI front-panel buttons Looked at how to program them 2 examples for practice