GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.

Slides:



Advertisements
Similar presentations
Engineering H192 - Computer Programming The Ohio State University Gateway Engineering Education Coalition Lect 19P. 1Winter Quarter MATLAB: Script and.
Advertisements

1. Definition 2. Creating Cell Arrays 3. Augmenting Cell Arrays 4. Referencing Cell Arrays 5. Special case 6. Spreadsheets 1.
EGR 106 – Week 2 – Arrays & Scripts Brief review of last week Arrays: – Concept – Construction – Addressing Scripts and the editor Audio arrays Textbook.
General Computer Science for Engineers CISC 106 Lecture 08 Dr. John Cavazos Computer and Information Sciences 2/27/2009.
Macros Tutorial Week 20. Objectives By the end of this tutorial you should understand how to: Create macros Assign macros to events Associate macros with.
MATLAB Cell Arrays Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University.
Introduction to Array The fundamental unit of data in any MATLAB program is the array. 1. An array is a collection of data values organized into rows and.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Digital Image Processing Lecture3: Introduction to MATLAB.
Programming For Nuclear Engineers Lecture 12 MATLAB (3) 1.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
January 24, 2005 Lecture 3 - By P. Lin 1 CPET 190 Lecture 3 Problem Solving with MATLAB
M-files While commands can be entered directly to the command window, MATLAB also allows you to put commands in text files called M- files. M-files are.
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.
AN ENGINEER’S GUIDE TO MATLAB
MATLAB File Management. MATLAB User File Management Matlab provides a group of commands to manage user files. For more information, type help iofun. pwd.
Functions General Example (+1return values, +1 parameters) 1. The client's wish 2. Creating the function 1. Function's name, Parameter list, Return-info,
Programming with Microsoft Visual Basic 2012 Chapter 12: Web Applications.
Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 4.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
WEEK 3 AND 4 USING CLIENT-SIDE SCRIPTS TO ENHANCE WEB APPLICATIONS.
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.
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
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (3): MATLAB Environment (Chapter 1)
1 Functions 1 Parameter, 1 Return-Value 1. The problem 2. Recall the layout 3. Create the definition 4. "Flow" of data 5. Testing 6. Projects 1 and 2.
1 Lab of COMP 406 Teaching Assistant: Pei-Yuan Zhou Contact: Lab 1: 12 Sep., 2014 Introduction of Matlab (I)
1. Reminder of Symbols 2. Dialog Boxes 3. listdlg() 4. msgbox() 5. questdlg() 6. menu() Dialog Boxes Applications of Cell-Arrays 1.
Introduction to Engineering MATLAB – 6 Script Files - 1 Agenda Script files.
1.Reminder of Symbols 2.Dialog Boxes 3.Output-centric dialogs 4.Input-centric dialogs Dialog Boxes Applications of Cell Arrays 1.
Using Client-Side Scripts to Enhance Web Applications 1.
What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation tools. Others include Maple Mathematica MathCad.
 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.
Tutorial 51 Programming Structures Sequence - program instructions are processed, one after another, in the order in which they appear in the program Selection.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
FIX Eye FIX Eye Getting started: The guide EPAM Systems B2BITS.
Chapter 3 MATLAB Fundamentals Introduction to MATLAB Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Chapter 1 – Matlab Overview EGR1302. Desktop Command window Current Directory window Command History window Tabs to toggle between Current Directory &
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
GUI development with Matlab: GUI Front Panel Components GUI development with Matlab: Other GUI Components 1 Other GUI components In this section, we will.
CSE123 Lecture 3 Files and File ManagementScripts.
Lecture 20: Choosing the Right Tool for the Job. What is MATLAB? MATLAB is one of a number of commercially available, sophisticated mathematical computation.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 9 : Introduction to GUI & Revision Edward Cheung Room W311g.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
A simple classification problem Extract attributes Pattern Pattern recognition decision x C1 C2.
Files: By the end of this class you should be able to: Prepare for EXAM 1. create an ASCII file describe the nature of an ASCII text Use and describe string.
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.
MATLAB for Engineers, by Holly Moore. ISBN © 2007 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is.
Cell Arrays Lecture 2/8/ Data Types (Review) 2. General Concept 3. Using Cell-Arrays 1. Syntax/Symbols 2. Dialog Boxes 1.
Digital Image Processing Introduction to MATLAB. Background on MATLAB (Definition) MATLAB is a high-performance language for technical computing. The.
Introduction to Engineering MATLAB – 4 Arrays Agenda Creating arrays of numbers  Vectors: 1-D Arrays  Arrays: 2-D Arrays Array Addressing Strings & String.
Introduction to Files in VB Chapter 9.1, 9.3. Overview u Data Files  random access  sequential u Working with sequential files  open, read, write,
31/01/ Selection If selection construct.
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
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.
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
Release Numbers MATLAB is updated regularly
Matlab Training Session 4: Control, Flow and Functions
Dialog Boxes Applications of Cell-Arrays
Microsoft Excel A Spreadsheet Program.
Other Kinds of Arrays Chapter 11
WEB PROGRAMMING JavaScript.
Use of Mathematics using Technology (Maltlab)
CSCI N317 Computation for Scientific Applications Unit 1 – 1 MATLAB
Introduction to Programming
Presentation transcript:

GUI Input and Output Greg Reese, Ph.D Research Computing Support Group Academic Technology Services Miami University

GUI Input and Output © Greg Reese. All rights reserved 2

Terminology –GUI: Graphical User Interface –I/O: Input or Output Two ways to do user I/O, i.e., get input from the user or show output to the user) 1.In the command-line window 2.Using a GUI User I/O 3

Command line advantages Easy Can use if MATLAB graphics not available Automatically converts text input to number Command-line I/O 4

Graphical User Interface (GUI) advantages Fairly easy Modern (current users familiar with it) Clear, convenient displays Fun! Graphical I/O 5

Pre-defined dialog boxes 6 dialogCreate and display empty dialog box errordlgCreate and open error dialog box export2wsdlgExport variables to workspace helpdlgCreate and open help dialog box inputdlgCreate and open input dialog box listdlgCreate and open list-selection dialog box msgboxCreate and open message box printdlgPrint dialog box printpreviewPreview figure to print questdlgCreate and open question dialog box uigetdirOpen standard dialog box for selecting directory uigetfileOpen standard dialog box for retrieving files uigetprefSpecify and conditionally open dialog box according to user preference uiopenInteractively select file to open and load data uiputfileOpen standard dialog box for saving files uisaveInteractively save workspace variables to MAT-file uisetcolorOpen standard dialog box for setting object's ColorSpec uisetfontOpen standard dialog box for setting object's font characteristics waitbarOpen or update wait bar dialog box warndlgOpen warning dialog box (From MATLAB documentation)

Most pre-defined dialog boxes are for getting input from the user Pre-defined dialog boxes 7 dialogCreate and display empty dialog box export2wsdlgExport variables to workspace inputdlgCreate and open input dialog box listdlgCreate and open list-selection dialog box printdlgPrint dialog box questdlgCreate and open question dialog box uigetdirOpen standard dialog box for selecting directory uigetfileOpen standard dialog box for retrieving files uigetprefSpecify and conditionally open dialog box according to user preference uiopenInteractively select file to open and load data uiputfileOpen standard dialog box for saving files uisaveInteractively save workspace variables to MAT-file uisetcolorOpen standard dialog box for setting object's ColorSpec uisetfontOpen standard dialog box for setting object's font characteristics

Pre-defined dialog boxes 8 errordlgCreate and open error dialog box helpdlgCreate and open help dialog box msgboxCreate and open message box printpreviewPreview figure to print waitbarOpen or update wait bar dialog box warndlgOpen warning dialog box Some pre-defined dialog boxes are for showing output to the user

Pre-defined dialog boxes 9 Pre-defined dialog boxes are either modal or non-modal (modeless) Modal dialog box –Prevents user from going to any other window in program (including command line) until user closes box –If used in script or function, code keeps running! Use uiwait() to pause code –Examples: open file dialog, get user input dialog

Pre-defined dialog boxes 10 Non-modal (modeless) dialog box –Permits user to go to any other window in program (including command line) –If used in script or function, code keeps running! Use uiwait() to pause code –Examples: error dialog, message dialog

Input dialog box answer = inputdlg(prompt) prompt is a text string or cell array containing prompts answer is cell array, same size as prompt Dialog box is modal (Text strings and cell arrays discussed in other lectures) GUI input 11

Example >> name=inputdlg( 'Full name' ) name = 'Greg Reese' >> whos name Name Size Bytes Class Attributes name 1x1 132 cell >> n = name{1} n = Greg Reese >> whos n Name Size Bytes Class Attributes n 1x10 20 char GUI input 12

Canceling returns empty cell array >> name=inputdlg('Full name' ) name = {} >> isempty( name ) ans = 1 GUI input 13

Numerals returned as text, i.e., not converted to numbers – Use str2double or str2num to convert >> weight=inputdlg('Weight' ) weight = '212.5' >> w = weight{1}; >> whos w Name Size Bytes Class Attributes w 1x5 10 char >> w = str2double( weight{1} ); >> whos w Name Size Bytes Class Attributes w 1x1 8 double GUI input 14

Try it Put up an input box that asks for the user's car manufacturer and display the string "Your car was made by xxx" where "xxx" is the name the user entered. Hint: concatenate the first part of the sentence with the user's response and display the result with disp() >> name = inputdlg( 'Your car''s manufacturer' ) name = 'Toyota' >> disp( [ 'Your car was made by ' name{1} ] ); Your car was made by Toyota GUI input 15 Note braces

str2double() Call as x = str2double('str') str is a string that is text representation of one real or complex number –x is a double-precision number –if str doesn't represent a number, x is NaN Call as x = str2double( C ) C is a cell array of strings –x is an array of double-precision numbers –x is same size as C GUI input 16

str2num() Call as x = str2num('str') str is a string that is text representation of a scalar or matrix of real or complex numbers –x is same size as matrix in str –if str not correct, x is empty matrix –str can contain one or more numbers separated by spaces, commas, or semicolons Examples from MATLAB help GUI input 17 String InputNumeric OutputOutput Class '500'5001-by-1 scalar double ' '500, 250, 125, 671-by-4 row vector of double '500; 250; 125; 62.5' by-1 column vector of double ' ; 53:56' by-5 matrix of double '12e-3 5.9e-3' vector of double 'uint16(500)'50016–bit unsigned integer

Variation 1 - add title to box answer = inputdlg(prompt,dlg_title) dlg_title – title of dialog box >> name = inputdlg( 'Name', 'Character Information' ) name = 'Suleiman the Magnificent' GUI input 18 Title doesn't appear fully in Windows 7 (MATLAB bug!)

Variation 2 - number of entered lines answer = inputdlg(prompt,dlg_title,num_lines) num_lines – number of lines user can enter –See Help if have multiple prompts >> name = inputdlg( 'Names', 'Character Information', 3 ) name = [3x18 char] >> name{1} ans = Voldemort Dark Lord Tom Marvolo Riddle GUI input 19

Variation 3 - default value answer = inputdlg(prompt,dlg_title,… num_lines,defAns) defAns – default answer to display –See Help if have multiple prompts >> name = inputdlg( 'Favorite character', … 'Character Information', 1, 'Hermione' ) ??? Error using ==> inputdlg at 113 Default Answer must be a cell array of strings. >> name = inputdlg( 'Favorite character',… 'Character Information', 1, {'Hermione'} ) name = 'Hermione' GUI input 20

Variation 4 - miscellaneous options answer = inputdlg(prompt,dlg_title,… num_lines,defAns,options) options – if 'on', can resize box horizontally –See Help for other options options! >> name = inputdlg( 'Favorite character',… 'Character Information', 1,{'Hermione'} ); >> name = inputdlg( 'Favorite character',… 'Character Information', 1,{'Hermione'}, 'on' ); GUI input 21

Try it Make this dialog box and print the user's input as "John Lennon's bride is xxx" where "xxx" is what the user entered. >> name=inputdlg( 'John Lennon''s?', 'Brides' ); >> disp( [ 'John Lennon''s bride is ' name{1} ] ) John Lennon's bride is Yoko Ono GUI input 22

Question dialog box button = questdlg( question, title ) Lets user answer by pressing buttons –question is a text string or cell array – title is text string displayed in box's title bar – by default, there are three buttons: 'Yes', 'No', or 'Cancel' – button is text string set to one of above three values, or empty if user closed box – dialog box is modal GUI input 23

Example >> button = questdlg( 'Save in default folder?',... 'Location of results' ); >> if strcmp( button, 'Yes' ) disp( 'Results stored in default folder' ); elseif strcmp( button, 'No' ) folder = uigetdir; else disp( 'No results stored' ); end Results stored in default folder GUI input 24 Pressing Yes button makes this output

Variations Can specify default button Can specify text and defaults for two buttons Can specify text and defaults for three buttons Can specify miscellaneous options See Help for more information GUI input 25

Variation - specify two buttons button = questdlg( question, title, str1, str2, default ) –str1 and str2 are a text strings for the two buttons –default is str1 or str2 and specifies which button is initially selected Try it Make this dialog box and display the label of the chosen button >> questdlg( 'Which dessert do you like better?',... 'Food survey', 'Pie', 'Ice cream', 'Ice cream' ) ans = Pie GUI input 26

Some predefined dialog boxes used to get specific types of input Examples: select directory, select file, specify color GUI input 27

Standard dialog box for getting file name fileName = uigetfile Displays list of files in current folder for user to select If file name valid and file exists, returns file name as character array. Otherwise, displays error message and returns to list If user clicks "Cancel" or closes box, returns 0 (not empty cell!) Dialog box is modal GUI input 28

Example >> fileName = uigetfile; >> if ischar( fileName )... disp( ['File: ' fileName] );... else disp( 'User canceled' ); end File: uniqueId_assignment2.m GUI input 29

Variation 1 fileName = uigetfile( FilterSpec ) fileName = uigetfile( FilterSpec,... DialogTitle ) FilterSpec - one or more file specifications, usually with wildcard (*) DialogTitle - title of dialog box See help on uigetfile() for details of FilterSpec GUI input 30

Try it Make a dialog box whose title is "MATLAB m-files" and whose filter specification is "*.m". Call it and display the result >> fileName = uigetfile( '*.m',... 'MATLAB m-files' ) fileName = assignment2_solution.m GUI input 31

Variation 2 [ fileName pathName ] = uigetfile() [ fileName pathName ] = uigetfile( FilterSpec ) [ fileName pathName ] = uigetfile( FilterSpec,... DialogTitle ) fileName - name and extension of chosen file pathName - path GUI input 32

Try it Make a dialog box whose title is "MATLAB m-files" and whose filter specification is "*.m". Maneuver to a different folder, select an m-file, and display the result GUI input 33

Try it >> [ fileName pathName ] = uigetfile(... '*.m', 'MATLAB m-files' ) fileName = cell_char_compare.m pathName = C:\Greg\CSA 441\2009\ GUI input 34

There are a few pre-defined dialog boxes to get special kinds of input. One example is selecting a color. Use uisetcolor() to do this Try it >> plot(1:10) GUI input 35

Try it >> c = uisetcolor; %pick obnoxious color >> GUI input 36

Try it >> axes( 'color', c ) GUI input 37

38 GUI Input Questions?

Message dialog box msgbox( message ) Displays text to user –message is a text string, text matrix or string array – Text is automatically wrapped to fit in box – User presses "Okay" button to close box Program does not stop executing while waiting for user to close box – Dialog box is non-modal (code keeps on running) Use uiwait() to pause code GUI output 39

Try it Call msgbox to display "Passed!", type some other MATLAB commands, then close the message box >> msgbox( 'Passed!' ) >> pwd ans = c:\greg\csa 441\2010\lectures >> date ans = 09-Jul-2010 >> GUI output 40

uiwait() makes program stop until message box is closed. Two ways to use: >> h = uiwait( msgbox('Hello World')); >> uiwait( h ); or >> uiwait( msgbox('Hello World')); Try it Call msgbox within uiwait() and notice that don't get prompt in command window >> uiwait( msgbox( 'Passed!' ) ) >> GUI output 41 Doesn't appear until message box closed

Example keepLooping = true; while keepLooping answer=inputdlg( 'Enter two characters'); if length( answer{1} ) ~= 2 h = errordlg( 'Enter only two characters' ); uiwait( h ); else keepLooping = false; end GUI output 42

Variation 1 msgbox( message, title ) title is title of message box Try it Display this message box and then close it >> msgbox( 'You passed', 'RESULT' ) GUI output 43

Variation 2 msgbox( message, title, icon ) icon specifies an icon to display – 'error' – 'help' – 'warn' – 'custom' (specify your own) – 'none' (no icon. This is the default) GUI output 44

Variation 2 Try it Display this message box and then close it >> msgbox( 'You failed the written part of the exam',... 'RESULT', 'warn' ) GUI output 45

Some predefined dialog boxes for output are errordlg - Display errors printpreview - Show current figure as it will print waitbar - Open or update a wait bar (progress bar) warndlg - Display warning All are non-modal GUI output 46

47 GUI Input and Output Questions?

48 The End