The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 9 : Introduction to GUI & Revision Edward Cheung Room W311g.

Slides:



Advertisements
Similar presentations
WEB DESIGN TABLES, PAGE LAYOUT AND FORMS. Page Layout Page Layout is an important part of web design Why do you think your page layout is important?
Advertisements

Introduction to Matlab
Introduction to Matlab Workshop Matthew Johnson, Economics October 17, /13/20151.
Introduction to MATLAB for Biomedical Engineering BME 1008 Introduction to Biomedical Engineering FIU, Spring 2015 Lesson 2: Element-wise vs. matrix operations.
Using Macros and Visual Basic for Applications (VBA) with Excel
© 2002 ComputerPREP, Inc. All rights reserved. Excel 2000: Customizing Excel and Using Macros.
Tutorial 12: Enhancing Excel with Visual Basic for Applications
The Web Warrior Guide to Web Design Technologies
Intermediate Level Course. Text Format The text styles, bold, italics, underlining, superscript and subscript, can be easily added to selected text. Text.
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)
EGR 106 – Week 2 – Arrays Definition, size, and terminology Construction methods Addressing and sub-arrays Some useful functions for arrays Character arrays.
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
Introduction to MATLAB MECH 300H Spring Starting of MATLAB.
Quark QuarkXPress 4 Foundation Level Course. What is QuarkXPress? This courseware teaches the fundamentals of QuarkXPress 4.1. It is a page layout application.
SPSS Statistical Package for the Social Sciences is a statistical analysis and data management software package. SPSS can take data from almost any type.
Introduction to Matlab Jianguo Wang CSSCR September 2009.
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.
Matlab tutorial course Lesson 2: Arrays and data types
Chapter 5 Java Script And Forms JavaScript, Third Edition.
Chapter 6: Forms JavaScript - Introductory. Previewing the Product Registration Form.
Word Processing ADE100- Computer Literacy Lecture 12.
Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB.
Nonparametric Econometrics1 Intro to Matlab for Data Analysis and Statistical Modeling.
Department of Mechanical Engineering, LSUSession VII MATLAB Tutorials Session VIII Graphical User Interface using MATLAB Rajeev Madazhy
Introduction to the Graphical User Interface (GUI) in MATLAB
Objectives Understand what MATLAB is and why it is widely used in engineering and science Start the MATLAB program and solve simple problems in the command.
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
Creating a Web Site to Gather Data and Conduct Research.
ELG 3120 Signal and System Analysis 1 Introduction to MATLAB TAs Wei Zhang Ozgur Ekici (Section A)(Section B) ELG 3120 Lab Tutorial 1.
Introduction to Matlab & Data Analysis
GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room A, Chris Hill, Room ,
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
Chapter 8 Collecting Data with Forms. Chapter 8 Lessons Introduction 1.Plan and create a form 2.Edit and format a form 3.Work with form objects 4.Test.
Matlab Programming for Engineers Dr. Bashir NOURI Introduction to Matlab Matlab Basics Branching Statements Loops User Defined Functions Additional Data.
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.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
Matlab 14.html Cost: $100 Available in labs on Windows and Unix machines.
Graphic User Interfaces (GUI) GUI provides a way to interact friendly with possibly complex programs. There are two types of GUI: - MDI: multiple document.
Formatting WorksheetsFormatting Worksheets Lesson 7.
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.
3 Copyright © 2004, Oracle. All rights reserved. Working in the Forms Developer Environment.
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.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
Introduction to Matlab  Matlab is a software package for technical computation.  Matlab allows you to solve many numerical problems including - arrays.
Chapter 3 Automating Your Work. It is frustrating when you have to type the same passage of text repeatedly. For example your name and address. Word includes.
INTRODUCTION TO MATLAB DAVID COOPER SUMMER Course Layout SundayMondayTuesdayWednesdayThursdayFridaySaturday 67 Intro 89 Scripts 1011 Work
Introducing Dreamweaver. Dreamweaver The web development application used to create web pages Part of the Adobe creative suite.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
Project Planning Defining the project Software specification Development stages Software testing.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 7 : M-file Programming I Edward Cheung Room W311g 2008.
Math 252: Math Modeling Eli Goldwyn Introduction to MATLAB.
MATLAB and SimulinkLecture 61 To days Outline Graphical User Interface (GUI) Exercise on this days topics.
Introduction to Programming on MATLAB Ecological Modeling Course Sep 11th, 2006.
IE 411/511: Visual Programming for Industrial Applications Lecture Notes #2 Introduction to the Visual Basic Express 2010 Integrated Development Environment.
An Introduction to Programming in Matlab Emily Blumenthal
Working in the Forms Developer Environment
Graphical User Interface in MATLAB
Matlab Workshop 9/22/2018.
StatLab Matlab Workshop
MATH 493 Introduction to MATLAB
StatLab Workshop: Intro to Matlab for Data Analysis and Statistical Modeling 11/29/2018.
Presentation transcript:

The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 9 : Introduction to GUI & Revision Edward Cheung Room W311g 2008m

2 Graphical User Interface GUI is the point of contact for human machine interface GUI incorporates objects such as Windows, icons, buttons menus and text Selecting or activating these objects causes the generation of an input event Application that provides GUI are more user friendly and easier to learn and use compare with command line interface (CLI) Simple GUI Output - Display Message Box  Example >>msgbox('Hello')

3 Default Dialog Boxes >>% a default warning box Warndlg Other default warning boxes are:- errordlg helpdlg warndlg

4 questdlg Create and display question dialog box Syntax:- button = questdlg('qstring','title','str1','str2','de fault') The dialog has three default buttons, Yes, No, and Cancel. >>answer=questdlg('Continue?'); Example: >> question='Do you want to continue?'; >> answer=questdlg(question,'Game Over','Yes','No','Help','Yes');

5 Cell arrays An array in which each element is a cell or bin Each cell can contain an array or any data type Group data sets that are related but with different dimensions Mathematical operations on cell array must be addressed to the contents of a cell Curly brackets {} is the cell array constructor and straight brackets [] is the standard array constructor Example:- Create & access a cell array with 4 elements:- >> A=[1 2 3;4 5 6;7 8 9]; B=2+5j; C=1:5; D=['A 2x2 Cell Array‘]; % example continue on next page

6 Example on Cell Array >> AA={A B; C D} % Form Cell Array with 4 elements AA = [3x3 double] [ i] [1x5 double] 'A 2x2 Cell Array' >> AA{1} % get first element of AA ans = >> AB={AA pi} % Form Cell Array AB with AA & pi AB = {2x2 cell} [3.1416] >> AB{1}(1,1) % a mixture of brackets to address elements ans = [3x3 double] >> AB{1}{1,1} % get first element of AA ans = % can use celldisp function to show entire array

7 Structure Array Use much like a database Similar to cell array, instead of using indexing methods as in other MatLab arrays, we can address the elements by field name Information in the structure array can be access using the array name, field name and the index number Stucture field names must begin with a letter and are case sensitive In MatLab, only Cell array and structure array can be used to manipulate a mixture of different data types

8 Structure Array Example:- Define a structure array using elements in last example. >> new_stru.matA=A; >> new_stru.strD=D; >> new_stru.complexB=B; >> new_stru.vectorC=C new_stru = matA: [3x3 double] strD: 'A 2x2 Cell Array' complexB: i vectorC: [ ]

9 inputdlg Create input dialog box Answer=inputdlg(prompt,title,lineNo,DefAns) lineNo specifies the number of lines for each user entered value. lineNo can be a scalar, column vector, or matrix.  If lineNo is a scalar, it applies to all prompts.  If lineNo is a column vector, each element specifies the number of lines of input for a prompt.  If lineNo is a matrix, it should be size m-by-2, where m is the number of prompts on the dialog box. Each row refers to a prompt. The first column specifies the number of lines of input for a prompt. The second column specifies the width of the field in characters.

10 Example prompt={'Input function:','Input color:','Input Limit:'}; title='Plot function'; lines=1; defans={'sin(x)','r','2*pi'}; answers=inputdlg(prompt,title,lines,defans); x=0:0.1:str2num(answer{3}); y=eval(answers{1}); figure; plot(x,y,answer{2});

11 Other Dialog Box Functions >> lookfor 'dialog box' AXLIMDLG Axes limits dialog box. ERRORDLG Error dialog box. HELPDLG Help dialog box. INPUTDLG Input dialog box. LAYOUT script to define dialog box layout parameters. LISTDLG List selection dialog box. MATQDLG Workspace transfer dialog box. PAGEDLG Page position dialog box. PRINTDLG Print dialog box. QUESTDLG Question dialog box. TABDLG Create and manage tabbed dialog box. UIGETFILE Standard open file dialog box. UIGETPREF question dialog box with preference support UIPUTFILE Standard save file dialog box. UISETCOLOR Color selection dialog box. UISETFONT Font selection dialog box. WARNDLG Warning dialog box.

12 uicontrol creates a user interface control in the current figure window and returns a handle to it. h= uicontrol %default UI control get (h) % a list of properties of h get (h,'style') set (h,'style') % set the style of h uicontrol('PropertyName1',value1,'PropertyName2,' value2,...) Help uicontrol Help set

13 Callbacks Callbacks are statements that get executed in the command window when an UI element is activated Example: >> uicontrol ('string','Start plot', 'Callback', 'surf(membrane)') Callback control is a routine that executes whenever the uicontrol object has been activiated. The example creates a uicontrol (default style is pushbutton) and mark the button with text ‘Start Plot’. When this button is being pressed, the command surf(membrane) is executed and a plot will be generated in the workspace.

14 GUIDE Graphical User Interface Development Environment (GUIDE) is a toolset consists of a Layout Editor and tools that can be used to add and arrange objects in a “figure” window (untitled figure). The following tools can be accessed from the Layout Editor. Alignment Tool - align objects with respect to each other. Menu Editor - create window menus and context menus. Property Inspector - inspect and set property values. Object Browser - observe a hierarchical list of the Handle Graphics Component Palette – UI controls in the current MATLAB session. To start the Layout Editor New  File  GUI or enter >>guide at the command prompt

15 GUI files GUIDE stores the GUI in two files:- fig-file – a type of mat file contain GUI layout & components m-file – a function file contains initialization code & templates for callbacks that are needed to control GUI behaviour. You must add the callbacks to this file. GUIDE automatically opens this file in the editor when you save your GUI the first time. fig-file and the m-file must have the same name. Layout editor – place the components on UI and save in fig file

16 GUI m-file Structure Major sections of the GUI m-file are ordered as follows:- Comments Initialization  GUIDE initialization tasks, Do Not edit this code Opening function  Perform initialization tasks before user has access to UI Output function  Returns outputs to CLI Callbacks  Component and figure callbacks corresponding to events Utility or helper functions  Functions that are not associated with an event

17 Quiz Next Week 30% of total marks for this module 30 multiple choice questions 45 minutes Open notes and NO discussion with your neighbour A list of commands is given at the last few pages of the workbook that will be provided as usual On some commands that we may not covered in this training course, you should call help wisely. Other assessment:-  Workshop report, 1 page, submit to mailbox before 8-Dec  You can do this after the quiz  Keep a copy of the workshop report for logbook submission due 4 weeks after summer term.

18 The colon operator >>A=0:pi/4:pi A = >> 100:-7:55 ans = >> 55:7:100 ans =

19 Use End as a subscript >> a=[1:3;10:10:30;100:100:300] a = >> a(end,end) ans = 300 >> a(1,end) ans = 3 >> a(end,1) ans = 100 >> a(end-1,end) ans = 30 >> a(end,end-1) ans = 200 >> a(end-5) ans = 2

20 Matrix manipulation & Transpose >> a(1:end-3) ans = >> b=(a(1:end-3))' b =

21 Colon & matrix reduction % Make a into a row vector with colon >>a(:)' ans = Examples on Matrix Reduction using colon  A(3,:)=[] % delete the third row in A  A(:,2:5)=[] % delete column 2 to 5 in A  A([1 4],:)=[] % delete 1 st & 4 th rows in A

22 Replicate a matrix >> a=[1 2 ; 3 4]; >>repmat(a,3,3) ans = Useful matrix generators:- zeros, ones, rand, randn, eye

23 Transpose for complex number >> z=[1+2i,2+4i] z = i i >> z' ans = i i >> z.' ans = i i Elements are changed into its complex conjugate. Use.’ to avoid changing elements into its complex conjugate when transpose if needed

Example on nested For loop % Create a n=5 symmetrical matrix A(n,n) with element (k,m) equals to k/m for m>=k n=5; A=eye(n); for m=2:n for k=1:m-1 A(k,m)=k/m; A(m,k)=k/m; end 24 >>A =

25 Interactive Curve Fitting % Example:- 2D interactive curve fitting % Figures -> Tools -> Basic Curve Fitting x=0:7 y=[0,11,44,58,77,85,95,97]; plot(x,y,'o') axis([0,7,0,100])