Part #10. AE0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

Similar documents
Data Analysis in Geophysics ESCI Class 17. Bob Smalley. More Matlab.

Purpose: How to train an MLP neural network in MATLAB environment!

Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Still More About Matlab GUI s (v. 1.3) Popup Menus. Popup Menu Exercise. Still More GUI Info - GE /29/2012. Copyright C. S. Tritt, Ph.D.

Department of Electrical Engineering, Technion IIT Signal and Image Processing Laboratory. Yair Moshe

LEARNING TO PROGRAM WITH MATLAB. Building GUI Tools. Wiley. University of Notre Dame. Craig S. Lent Department of Electrical Engineering

MATLAB for biologists Lecture 6

CNBC Matlab Mini-Course

m-files Matlab offers this feature through m-files, which are ascii text files containing a set of Matlab commands.

Part #6. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Computational Methods of Scientific Programming Fall 2008

Part #3. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

Computational Methods of Scientific Programming. Matlab Lecture 4 Lecturers Thomas A Herring Chris Hill

Computational Methods of Scientific Programming. Matlab Lecture 3 Lecturers Thomas A Herring Chris Hill

Introduction To MATLAB Interactive Graphics

Computational Methods of Scientific Programming

Part #5. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

The Language of Technical Computing. Computation. Visualization. Programming. Creating Graphical User Interfaces Version 1

BUILDING A MATLAB GUI. Education Transfer Plan Seyyed Khandani, Ph.D. IISME 2014

Information for Candidates. Test Format

DEVELOPMENT OF MOTOR CONTROL USING GRAPHICAL USER INTERFACE KHAIRUL ANUAR BIN ARIS UNIVERSITY MALAYSIA PAHANG

SBT 645 Introduction to Scientific Computing in Sports Science #5

Part #12. AE0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

MATLAB. The Language of Technical Computing. MATLAB Graphics Reference Version 5.1. Computation. Visualization. Programming

INTRODUCTION TO MATLAB INTERACTIVE GRAPHICS EXERCISES

Signal and Systems. Matlab GUI based analysis. XpertSolver.com

INTRODUCTION TO THE MATLAB APPLICATION DESIGNER EXERCISES

% Edit the above text to modify the response to help Video_Player. % Last Modified by GUIDE v May :38:12

CANDIDATE INFORMATION

Homeworks on FFT Instr. and Meas. for Communication Systems- Gianfranco Miele. Name Surname

7 HANDLE GRAPHICS IN THIS CHAPTER 7.1 GRAPHICS OBJECTS 7.2 GRAPHICS OBJECTS HIERARCHY 7.3 GRAPHICS OBJECTS HANDLES 7.4 PROPERTIES 7.

Special Topics II: Graphical User Interfaces (GUIs)

Review: Event Driven Programming & GUI. CSCE155N Matlab Fall 2016

Part #8. AE0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

Introduction to Matlab

Building a Graphical User Interface

Graphics and GUIs. with MATLAB THIRD EDITION by Chapman & Hall/CRC

MATLAB. Creating Graphical User Interfaces Version 7. The Language of Technical Computing

Unit 2: Managing Views

Graphical User Interface. GUI in MATLAB. Eng. Banan Ahmad Allaqta

Seagate Crystal Reports 8 and Hyperion Essbase

Tim Love. July 24, Introduction 2. 2 Info and help commands 2

Lab 8: Conditional Statements with Multiple Branches (please develop programs individually)

P3e REPORT WRITER CREATING A BLANK REPORT

Exploring Microsoft Office Word 2007

A0B17MTB Matlab. Part #2. Miloslav Čapek Viktor Adler, Pavel Valtr. Department of Electromagnetic Field B2-634, Prague

Part #7. A0B17MTB Matlab. Miloslav Čapek Viktor Adler, Pavel Valtr, Filip Kozák

3. Centralize your title. To do this, click the Center button on the tab s paragraph group.

There are two ways to launch Graphical User Interface (GUI). You can either

Working with PDF s. To open a recent file on the Start screen, double click on the file name.

Using Reports. BrioQuery 6 Level II

CRITERION Vantage 3 Admin Training Manual Contents Introduction 5

SciGraphica. Tutorial Manual - Tutorials 1and 2 Version 0.8.0

Board Options. Modified by Phil Loughhead on 27-Jan Parent page: PCB Dialogs. Old Content - visit altium.com/documentation

Bombardier Business Aircraft Customer Services. Technical Publications. SmartPubs Viewer 3.0 User Guide. Updated January 2013 [2013]

OpenForms360 Validation User Guide Notable Solutions Inc.

Enterprise Architect. User Guide Series. Testing. Author: Sparx Systems Date: 15/07/2016 Version: 1.0 CREATED WITH

Table of Contents Lesson 1: Introduction to the New Interface... 2 Lesson 2: Prepare to Work with Office

Enterprise Architect. User Guide Series. Testing. Author: Sparx Systems. Date: 10/05/2018. Version: 1.0 CREATED WITH

Creating Universally Designed Word 2013 Documents - Quick Start Guide

SAS Visual Analytics 8.2: Working with Report Content

Technical White Paper

DEPARTMENT OF ELECTROMAGNETIC FIELD CZECH TECHNICAL UNIVERSITY IN PRAGUE CZECH REPUBLIC

Table of Contents The University of Akron These materials were developed and are owned by The University of Akron. All rights reserved.

AURUM Metro Navigation

OCTAVO An Object Oriented GUI Framework

Text box. Command button. 1. Click the tool for the control you choose to draw in this case, the text box.

The 3D Parts Catalog Operator s s Guide

Working with Tables in Word 2010

GAZIANTEP UNIVERSITY INFORMATICS SECTION SEMETER

Instructions for Using PDF Tests and Journals

LAMPIRAN 1. Percobaan

Cascading Style Sheets (CSS)

Microsoft Office Word 2016 for Mac

Introduction to Microsoft Publisher

PROGRAMMING AND ENGINEERING COMPUTING WITH MATLAB Huei-Huang Lee SDC. Better Textbooks. Lower Prices.

VBA Collections A Group of Similar Objects that Share Common Properties, Methods and

GRAPHICS AND VISUALISATION WITH MATLAB Part 2

V G23 Rev: 12/04

Hour of Code: Teacher Guide

Tutorials. Lesson 3 Work with Text

MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

ELO. ELO Dropzone. Document Management and Archiving Software. September ELO Digital Office GmbH.

1. Cascading Style Sheet and JavaScript

10.4 Inputs without Waiting

Computational Methods of Scientific Programming Fall 2007

THE EXCEL ENVIRONMENT... 1 EDITING...

Creating a Test in TAG

Document Manager 6.0 Users Manual by Scanlon Associates

Working with the RTF Generator

CHRIST THE KING BOYS MATRIC HR. SEC. SCHOOL, KUMBAKONAM CHAPTER 2 TEXT FORMATTING

Matlab Tutorial 1: Working with variables, arrays, and plotting

Introduction to Information Technology

ADD A 3-D PIE CHART TO THE WORKBOOK

Graphical User Interface Canvas Frame Event structure Platform-free GUI operations Operator << Operator >> Operator = Operator ~ Operator + Operator

The user-defined grids can only be defined and managed from within the Grid Manager dialog.

Tutorial 3: Using the Waveform Viewer Introduces the basics of using the waveform viewer. Read Tutorial SIMPLIS Tutorials SIMPLIS provide a range of t

OSDC Series Pattern Editor Ped/Win User s Manual

GUI Building for Test & Measurement Applications

CellaVision Proficiency Software

Transcription:

AE0B17MTB Matlab Part #10 Miloslav Čapek miloslav.capek@fel.cvut.cz Viktor Adler, Pavel Valtr, Filip Kozák Department of Electromagnetic Field B2-634, Prague

Learning how to GUI #2 user? GUI function3 function1 function2!!! Attention: CHANGES IN GRAPHICS SINCE MATLAB R2014b!!! 2

Techniques of GUI design - sorting there exist several approaches (methodologies) to create GUI design using GUIDE tool not recommended design using App Designer (from R2016a) new graphic objects ('old' objects are not supported) >> guide >> appdesigner switch-board technique not recommended utilization of side and nested functions as callback functions standard fully OOP approach (including functional part of the code) ideal 3

Callback function there are user-evoked events defined related to each object (button click, list selection,...) these events are served by so called callback functions in other words, when user pushes button, callback function of this event is activated (if defined). when GUI is not to be static, it has to contain at least one callback function callback function is stored as an object property it is possible to change it, delete it, copy it etc. 4

Evaluation of callback function callback function is evaluated as a handle function hb = uicontrol('style', 'pushbutton', 'String', 'Plot line') % Calling function using handle function set(hb, 'Callback', @myfunc) function myfunc(hobject, callbackdata) % Callback function always adds two basic inputs hobject callbackdata % reference to the object raising the callback % object describing event 5

Evaluation of callback function callback function is evaluated as an anonymous function hb = uicontrol('style', 'pushbutton', 'String', 'Plot line') % TIP anonymous function can be used in the case of calling a function that doesn't support basic inputs of callback function set(hb, 'Callback', @(src, event)myfunc(inp)) function myfunc(inp) inp % the input are only variables defined by user 6

Evaluation of callback function callback function is evaluated as a handle function hb = uicontrol('style', 'pushbutton', 'String', 'Plot line') % Cell array, where first element is a handle function set(hb, 'Callback', {@myfunc, inp1,..., inpn}) function myfunc(hobject, callbackdata, inp1,..., inpn) % Basic inputs added to first positions again hobject callbackdata % reference to the object raising the callback % structure of various events (can be empty) inp1,..., inpn % other inputs 7

Evaluation of callback function Ex.: change background color of push button and change its label to 'Done' when clicked function GUI close all hbutt = uicontrol('units', 'normalized', 'Style', 'pushbutton', 'String',... 'pushbutton', 'ForegroundColor', 'white',... 'BackgroundColor', [0.7 0.2 0], 'FontWeight', 'bold',... 'FontSize', 11, 'Position', [0.1 0.65 0.15 0.1]); hbutt.callback = @pressbutton; end function pressbutton(scr, event) % scr and event are default parameters returned by callback functions % scr - callback source (button handle object in this case) % event - info on event raised (sometimes usefull) disp(scr); % check list object handle disp(event); % show info on raised event set(scr, 'String', 'Done', 'BackgroundColor', rand(1, 3)); end 8

Evaluation of callback function callback function is evaluated as a string hb = uicontrol('style', 'pushbutton', 'String', 'Plot line') hb.callback = 'plot(rand(20,3))'; very limited possibilities the string can contain variables as well only the variables from base Workspace are evaluated correctly GUI is usually created in functions source handle object is not available it is possible to call just scripts or main functions with predefined inputs 4/25/2018 2:28 PM 9

Callback functions list Callback CellEditCallback CellSelectionCallback ButtonDownFcn ClickedCallback CreateFcn, DeleteFcn OffCallback, OnCallback ResizeFcn (<R2014b) SelectionChangeFcn KeyPressFcn KeyReleaseFcn WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn WindowKeyPressFcn WindowKeyReleaseFcn WindowScrollWheelFcn CloseRequestFcn context menu, uiobjects uitable uitable axes, figure, button group, panel, uiobjects push tool, toggle tool axes, button group, context menu, figure, menu, panel, uiobjects, toggle tool figure, panel, button group button group figure, uiobjects figure figure figure figure figure figure figure figure 10

Callback functions list Callback CellEditCallback CellSelectionCallback ButtonDownFcn ClickedCallback CreateFcn, DeleteFcn OffCallback, OnCallback SizeChangedFcn (>=R2014b) SelectionChangeFcn KeyPressFcn KeyReleaseFcn WindowButtonDownFcn WindowButtonMotionFcn WindowButtonUpFcn WindowKeyPressFcn WindowKeyReleaseFcn WindowScrollWheelFcn CloseRequestFcn context menu, uiobjects uitable uitable axes, figure, button group, panel, uiobjects push tool, toggle tool axes, button group, context menu, figure, menu, panel, uiobjects, toggle tool figure, panel, button group button group figure, uiobjects figure figure figure figure figure figure figure figure 11

Functions gcf, gca and gco serve to easily access identifiers of objects that are currently active, in particular: gcf returns identifier of current object figure gca returns identifier of current object axes gco returns identifier of the object that was last to mouse-click on (tolerance is 5 px) figure figref = gcf these functions can be used as input identifiers for other functions requiring reference to object figure or axes set(gcf,'color',[0 0 0]) 12

Exercise button callback create figure with button and text box when clicking on button background color of button changes to random and displays individual RGB components in text box 600 s 13

Exercise button, solution 14

Exercise mouse position create a text array showing mouse position over figure. figure's callback for mouse movement is WindowButtonMotionFcn mouse position can be found in figure property CurrentPoint 600 s 15

Function findobj finds an object(s) with required property returns reference to the object (or an array of references) >> fighndl = gcf; % fighndl = figure; >> axshndl = gca; % axshndl = figure; >> htx1 = uicontrol('style','text','string','hello','tag','tx1'); >> htx2 = uicontrol('style','text','string','test1','tag','tx2'); >> h = findobj('style','text','-and','tag','tx1') h = UIControl (tx1) with properties: Style: 'text' String: 'hello' BackgroundColor: [0.9400 0.9400 0.9400] Callback: '' Value: 0 Position: [20 20 60 20] Units: 'pixels' >> h = findobj('style','text') h = 2x1 UIControl array: UIControl UIControl (tx2) (tx1) Show all properties 16

Exercise keyboard scan create a text array that displays last key pressed information on the key pressed is to be found in event parameter figure's callback for pressing key is WindowKeyPressFcn get the reference to the text array using findobj 600 s 17

Function findall, allchild findall finds all graphic objects (including hidden) allchild finds all children of selected object (including hidden) handle_list can be for instance gcf, gca,... if handle_list is a identifier vector, Matlab returns cell array clc, clear, close all % figure with menu hfig = figure; % compare hfig.children get(hfig, 'Children') findobj('parent', hfig) allchild(hfig) findall(hfig, 'Parent', hfig) findall(hfig) clc, clear, close all % figure with menu hfig = figure('menubar', 'none'); % compare hfig.children get(hfig, 'Children') findobj('parent', hfig) allchild(hfig) findall(hfig, 'Parent', hfig) findall(hfig) 18

Function copyobj this function enables to have an influence on lifecycle of an object copies object and its descendants more >> doc copyobj >> hf = figure >> ha = axes >> hl1 = line([0.1 0.8], [0.5 0.5]) >> hl2 = copyobj(hl1,ha) >> set(hl2, 'YData', [0.4 0.6]) >> ishandle(hl1) && ishandle(hl2) ans = 1 19

Function delete, reset these functions enable to have an influence on lifecycle of an object delete removes file(s) or graphic object(s) together with its descendants >> delete(hf) % hf see previous example >> ishandle(hl1) && ishandle(hl2) ans = 0 reset sets all values of an object back to implicit values reset(h) 20

Advanced visualizing in Matlab function gobjects predefines variables % preallocation h = gobjects(3,1); function isgraphics() x = 1:10; y = sin(x); p = plot(x,y); ax = gca; h(1) = figure; h(2) = plot(1:10); h(3) = gca; class(h) arrayfun(@class, h,... 'UniformOutput', false) isgraphics([p, ax]) function ishandle finds out whether variable is a handle object >> fighandle = figure; >> ishandle(fighandle) >> doc Graphics Object Identification 21

Storing data in GUI how to store data in GUI? global variables (extreme case, keyword global) unacceptable using property UserData (depends on size of the application) acceptable using functions guidata or setappdata and getappdata suitable fully OOP access (including functional part of the code) ideal 22

Function guidata enables to store or get data the procedure is as follows: get data copy: data = guidata(object_handle) carry out data modification / calculation required if the data is changed, store guidata(object_handle,data) data is therefore related to a handle that exist during whole lifetime of GUI data is saved in object's parent figure 23

Function guidata >> hfig = figure('toolbar', 'none'); >> allfighndl = guihandles(hfig); >> guidata(hfig, allfighndl); function guihandles returns references of all visible objects in figure function mycallback() %... myallfighndl = guidata(gcbo); myallfighndl.time = clock; guidata(gcbo, myallfighndl); function gcbo returns reference of the object callback of which is being evaluated 24

Functions setappdata, getappdata setappdata: enables to define new data (pair name-value) for given application clc, clear, close all hfig = figure; hbutt = uicontrol('parent', hfig); setappdata(hbutt, 'speeda', rand(1, 10)); getappdata: enables to get previously defined data of selected object value = getappdata(hfig, 'speeda') % values is a structure values = getappdata(hndl) 25

Exercise mouse movements + buttons create application according to picture below button End terminates application Callback of uicontrol left and right mouse button click on figure changes font type of label Xposition and Y-position from normal to bold and vice versa WindowButtonDownFcn of figure and event input in the case checkbox is ticked, program displays cursor position Value of uicontrol and CurrentPoint of figure 600 s 26

Exercise mouse movements + buttons 27

Exercise mouse movements + buttons 28

Predefined dialog windows The most common operations used GUI are predefined the most common ones are displayed below (most of them): user helpdlg msgbox warndlg errordlg GUI inputdlg listdlg questdlg file uigetdir uigetfile uiopen file uiputfile uisave user waitbar 29

Function msgbox displays message for the user >> h = msgbox({'this is a message for Matlab students.',... 'Predefined functions save time',... 'Demonstration of msgbox usage.'}) 30

Function questdlg displays a question, returns answer >> query = questdlg('terminate application?',... 'End of application','yes','no','yes') 31

Function uigetfile user can select file(s) from file dialog box files can be filtered by their suffix >> [FileName,PathName] = uigetfile('*.m', 'Select the M-file'); 32

Function uiputfile opens dialog for file saving files can be filtered by their suffix >> [file,path] = uiputfile('*.mat', 'Save workspace as:',... 'defaultfile.mat') 33

Exercise saving into file save variable data from Workspace in a file using dialog box 400 s 34

Function waitbar displays state of a process h = waitbar(0, 'Please wait...'); nsteps = 1000; for k = 1:nsteps waitbar(k/nsteps); end close(h); 35

Design of a simple GUI #1 what the GUI should do (detailed description of functionality) what are the user inputs required outputs objects used (scheme of GUI, list of elements, design of tags and properties) callback functions, dynamic elements saving of identifiers and data in GUI programming style implementation of individual parts getting it to work, testing... 36

Discussed functions gcf, gca, gco findobj, findall, allchild copyobj delete, reset gobjects, ishandle, isgraphics helpdlg, msgbox, warndlg, errordlg inputdlg, listdlg, questdlg uigetdir, uigetfile, uiopen uiputfile, uisave waitbar guide guidata, setappdata, getappdata 37

Exercise displaying graph of a function create a GUI which shows a graph of a function defined by a user use try catch to eliminate erroneous inputs use function reset to clear graph before another drawing what function do you use to evaluate the text input? 600 s >> MTB_GUI1edit 38

Exercise displaying graph of a function 39

Exercise displaying graph of a function 25.04.2018 14:29 40

Thank you! ver. 9.1 (25/04/2018) Miloslav Čapek, Pavel Valtr miloslav.capek@fel.cvut.cz Apart from educational purposes at CTU, this document may be reproduced, stored or transmitted only with the prior permission of the authors. Document created as part of A0B17MTB course.