A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. >> sphere(100)

Slides:



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

Introduction to Macromedia Director 8.5 – Lingo
Microsoft Office XP Microsoft Excel
What is a Dialog box? A Dialog box is a window or “form” that contains other child windows or “controls” that have a specific appearances and pre-defined.
© 2010 Delmar, Cengage Learning Chapter 9: Using ActionScript.
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.
1 How to create GUI's in MatLAB Rigo Dicochea. 2 Introduction Graphical User Interface (GUI) MatLab provides Graphical User Interface Development Environment(GUIDE)
A Guide to Oracle9i1 Introduction To Forms Builder Chapter 5.
3D Game Programming All in One By Kenneth C. Finney.
Microsoft Excel 2010 Chapter 8
Chapter 4: Working with Windows Types of Windows –Program Windows –Message Boxes –Dialog Boxes Elements of a Window –Window Panes –Scroll Bars –Menus –Tool.
CA 121 Intro to Programming Tariq Aziz and Kevin Jones GUI Programming in Visual Studio.NET Chapter 3 Tariq Aziz and Kevin Jones.
Compunet Corporation Programming with Visual Basic.NET GUI Chapter 3 Week 13 Tariq Aziz and Kevin Jones.
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.
User Interface Design using jQuery Mobile CIS 136 Building Mobile Apps 1.
Access Tutorial 10 Automating Tasks with Macros
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.
Chapter 5 Review: Plotting Introduction to MATLAB 7 Engineering 161.
Chapter 5 Java Script And Forms JavaScript, Third Edition.
PLOTS AND FIGURES DAVID COOPER SUMMER Plots One of the primary uses for MATLAB is to be able to create publication quality figures from you data.
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
Matlab GUIs GUIDE.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 21 Fields and Forms.
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 --
Chapter 3: Using GUI Objects and the Visual Studio IDE.
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.
Domain 3 Understanding the Adobe Dreamweaver CS5 Interface.
GUI Widgets Jeff Offutt SWE 432 Design and Implementation of Software for the Web.
Graphic Objects figure axes 2D-plot 3D-plot axis labels title GUI objects pushbutton toggle edit text menu.
MA/CS 3751 Fall 2002 Lecture 24. MA/CS 3752 ginput ginput is a Matlab function which takes one argument input: number of points to select in the image.
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.
Computational Methods of Scientific Programming Lecturers Thomas A Herring, Room , Chris Hill, Room ,
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.
Introduction to MATLAB Damon Tomlin February 22, 2008 Lecture 3: Data Visualization & User Interfaces.
Graphical User Interfaces Tonga Institute of Higher Education.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. WORD 2007 M I C R O S O F T ® THE PROFESSIONAL APPROACH S E R I E S Lesson 15 Advanced Tables.
Creating Graphical User Interfaces (GUI’s) with MATLAB By Jeffrey A. Webb OSU Gateway Coalition Member.
WaveMaker Visual AJAX Studio 4.0 Training Basics: Building Your First Application Designer Basics.
Graphic User Interfaces (GUI) GUI provides a way to interact friendly with possibly complex programs. There are two types of GUI: - MDI: multiple document.
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.
Introduction to Matlab & Data Analysis 2015 In this tutorial we will: Build a practical application using GUIDE Learn more about graphical user interface.
Topics Introduction Scene Graphs
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Visual Basic Programming Introduction VB is one of the High level language VB has evolved from the BASIC language. BASIC stands for Beginners All-purpose.
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.
The Hong Kong Polytechnic University Industrial Centre 1 MatLAB Lesson 9 : Introduction to GUI & Revision Edward Cheung Room W311g.
EGR 115 Introduction to Computing for Engineers
Graphic User Interface Review of Lecture 1 to Lecture 6 C.F. Lu.
Introduction to Matlab Module #10 Page 1 Introduction to Matlab Module #10 – Creating Graphical User Interfaces Topics 1.Overview of GUI Development using.
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.
Lecture (7) Introduction to GUI Eng. Osama Talaat 1.
GUI Controls for Input Design Introduction –Most new applications being developed today include a GUI. This approach is influenced by a new trend in.
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.
Microsoft Visual C# 2010 Fourth Edition Chapter 3 Using GUI Objects and the Visual Studio IDE.
Graphical User Interfaces I
Topics Graphical User Interfaces Using the tkinter Module
Graphical User Interface in MATLAB
Chap 7. Building Java Graphical User Interfaces
More on Graphical User Interfaces
Graphical User Interfaces -- Introduction
AWT Components and Containers
Chapter 13 Sights and Sounds.
Topics Graphical User Interfaces Using the tkinter Module
Electrical and Computer Engineering Department SUNY – New Paltz
Presentation transcript:

A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. >> sphere(100)

A short intermission about function handles and cell arrays A MATLAB function may be referenced by a handle. s [XX YY ZZ] = feval(s,100)

Example function draw(function_handle, function_parameter) [XX YY ZZ] = feval(function_handle, function_parameter); surf_handle = surf(XX,YY,ZZ); ax = get(surf_handle,'parent'); shading(ax,'INTERP') What would be the result of: draw(s,100) ? ?

Cell arrays are similar to normal arrays … but They use curly brackets { } They store elements of different types

x = {s 6} x [6] x{1} ans x{2} ans = 6

Continuing with GUI

Graphic Objects figure axes 2D-plot 3D-plot axis labels title GUI objects pushbutton toggle edit text menu

The UIcontrols are common interface controlers Help us perform specific actions or set the variables for future actions Actions and options are selected by the mouse, some UIcontrols are also editable so we can use the keyboard as well Interface controllers

We can create UIcontrols simply by implementing the following syntax handle_to_UI=uicontrol(‘Property Name’,’Property Value’);

Interface controllers UIcontrol types are defined by their ‘style’ property: Check box 'checkbox'Editable text field 'edit' Toggle button 'toggle' 'Pop-up menus 'popupmenu' Push button 'pushbuttonList box 'listbox' Radio button 'radiobutton' Static text 'text' Slider 'slider'Frame 'frame'

Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty – ''

Example uicontrol('style','pushbutton','callback','close(gcf)');

Interface controllers are graphic objects Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty - '' Recommendation – always call a function that does what you want.

function closeCurrentFigure(hCallingButton,... eventData) close(gcf) End uicontrol('style','pushbutton',...

Interface controllers are graphic objects Essential properties: Callback – A string with one or more commands that is executed when the controller is activated. May be empty - '' Recommendation – always call a function that does what you want. Tag – a string that may be used as a unique identifier of the controller. h = findobj('Tag','1');

Essential properties : Units – 'pixels' (default) or 'norm' (recommended) or Position – The vector [Left-lower-corner-X Left-lower-corner-Y width height] If you want to use the 'norm' units you should declare it before the position is set.

Essential properties : Value – a scalar String UserData – a matrix

hToCheckBox = uicontrol('Style', 'checkbox',... 'Position',[ ],... 'String','Check Box example‘,... ‘Callback’,’’) Checkboxes allow the user to turn on/off a number of independent options Note: the position is measured in pixels from the left-bottom corner of the figure Checkboxes

Represented by the Value property : 1 for checked 0 for unchecked >>state=get(hToCheckBox,’Value’) These values correspond to the Max and Min properties of the uicontrol which by default are 1 and 0 respectively Checkbox state

Example function OnOffFrame uicontrol('style', 'toggle',... 'position', [ ],... 'backgroundColor‘, 'b',... 'foregroundColor', 'r',... 'tag', 'onOff',... 'string', 'on',... 'FontSize', 40,... 'callBack', 'userData', 1);

function OnOffFrame uicontrol('style', 'toggle',... 'position', [ ],... 'backgroundColor‘, 'b',... 'foregroundColor', 'r',... 'tag', 'onOff',... 'string', 'on',... 'FontSize', 40,... 'callBack', 'userData', 1); Cell array A handle to the function onOff

function OnOffFrame uicontrol(: : :); function onOff(hCallingButton, eventData) state = get(hCallingButton,'userData'); if (state) %on set(hCallingButton,... 'string', 'off',... 'backgroundColor', 'r',... 'foregroundColor', 'b',... 'userData', 0); else set(hCallingButton,'string', 'on',... 'backgroundColor', 'b',... 'foregroundColor', 'r',... 'userData', 1); end end

function OnOffFrame uicontrol(: : :); function onOff(hCallingButton, eventData) state = get(hCallingButton,'userData'); if (state) %on set(hCallingButton,... 'string', 'off',... 'backgroundColor', 'r',... 'foregroundColor', 'b',... 'userData', 0); else set(hCallingButton,'string', 'on',... 'backgroundColor', 'b',... 'foregroundColor', 'r',... 'userData', 1); end end A handle to the calling controller A matrix (in this case empty)

Graphic objects Figure Axes

UI controllers pushdown button toggle button radio buttons text editor text slider

UI menu

Initialize figure, UI controllers and menu my_first_GUI – flow chart

Initialize figure, UI controllers and menu my_first_GUI – flow chart Activated? Perform callback yes no UI 1 wait

Initialize figure, UI controllers and menu my_first_GUI – flow chart Activated? Perform callback yes no UI 1 wait Activated? Perform callback yes no UI 2 wait

Initialize figure, UI controllers and menu my_first_GUI – flow chart Activated? Perform callback yes no UI 1 wait Activated? Perform callback yes no UI 2 wait Kill? display? Calculate and update figure yes no yes no Get parameters from UI Close figure Main program

function run (the drawing engine) function draw (actually draws) my_first_GUI – flow of information t C axes handles edit uicontrol C slider uicontrol speed toggle uicontrol On/off pushButton uicontrol kill uimenu figure colormap radioButton uicontrol type

Step I – setting the scene function my_first_gui draw_figure(600,600) end

Step I – setting the scene function my_first_gui draw_figure(600,600) end function draw_figure(width, height) screen_size = get(0,'screenSize'); left = screen_size(1)+5; bottom = screen_size(4)-height-40;

Step I – setting the scene function my_first_gui draw_figure(600,600) end function draw_figure(width, height) screen_size = get(0,'screenSize'); left = screen_size(1)+5; bottom = screen_size(4)-height-40; figure('position',[left bottom width height],... 'menuBar','none'); end

Step II – subplots function my_first_gui draw_figure('the_figure',600,600) main_axes = subplot(7,7,[ ]); small_axes = subplot(7,7,[7 14]); end function draw_figure(tag, width, height) screen_size = get(0,'screenSize'); left = screen_size(1)+5; bottom = screen_size(4)-height-40; figure('position',[left bottom width height],... 'tag', tag,... 'menuBar','none'); end

Toggle buttons (or switches) are best suited for choosing between options like true/false, on/off and so on Buttons

Step III – the on/off button uicontrol('style','toggle',... 'position',[ ],... 'backgroundColor','b',... 'foregroundColor','r',... 'tag','onOff',... 'string','on',... 'userData',1); on

Step III – the on/off button function onOff(calling_button, eventData) state = get(calling_button,'userData'); if (state) %on set(calling_button,'string','off',... 'backgroundColor','r',... 'foregroundColor','b',... 'userData',0); else set(calling_button,'string','on',... 'backgroundColor','b',... 'foregroundColor','r',... 'userData',1); end end on

function onOff(calling_button, eventData) state = get(calling_button,'userData'); if (state) %on set(calling_button,'string','off',... 'backgroundColor','r',... 'foregroundColor','b',... 'userData',0); else set(calling_button,'string','on',... 'backgroundColor','b',... 'foregroundColor','r',... 'userData',1); end end on

Push buttons are designed to launch a specific action like starting or stopping an execution, resetting the content of a form etc. Buttons

uicontrol('style', 'pushbutton',... 'position',[ ],... 'backgroundColor','b',... 'foregroundColor','r',... 'tag','close',... 'string','close',... 'callBack', 'userData',0); Step IV– the close button on close

function close_all(calling_button, eventData) set(calling_button,'userData',1); end onclose

function close_all(calling_button, eventData) set(calling_button,'userData',1); end onclose Why don’t we close the figure?

Sliders Sliders provide an easy way to gradually change values between a given range. Three ways to move the slider

Sliders The user has three possible way to change the position of the slider 1.Click the arrow buttons => small value changes 2.Click the trough => large value changes 3.Click and drag the slider => depends on user The default changes are 1% and 10%

Sliders The range of the slider is defined with the Min and Max uicontrol properties. The amount of change related to an user click is controlled with the SliderStep property which is a two element vector ([ ] default) hToVertSlider= uicontrol('Style','slider',... 'Position',[ ],... 'Min',10,... 'Max',20,... 'Value ',15,... 'SliderStep',[ ],... 'Callback','') We must set a value between Min and Max

Sliders Given the setting from Min, Max and SliderStep the amount of change to the current Value are as follow: For an arrow click: Value = Value + SliderStep(1) * (Max – Min) 16 = * ( ) For a trough click: Value = Value + SliderStep(2) * (Max – Min) 17.5 = * ( )

Step V– the speed slider uicontrol('style','slider',.... 'position',[ ],... 'tag','speedSlider',... 'max',pi/2,... 'min',0.01,... 'value',pi/4);

Step V– the speed slider uicontrol('style','slider',.... 'position',[ ],... 'tag','speedSlider',... 'max',pi/2,... 'min',0.01,... 'value',pi/4); What about the callback?

Text and editable text Static texts are commonly used to give instructions or to display other controllers values (such as sliders) …’Style’,’text’,… Static text can not execute callbacks. Editable texts gets string input from the GUI user. When the user enters the edit field and change its content, only the String property is affected. Editable text can execute callbacks

Step VI – the text frame uicontrol('style','text',... 'string','C',... 'tag','C_title',... 'position',[ ],... 'backgroundColor','y'); What about the callback?

Step VII – the edit window uicontrol('style','edit',... 'string','1',... 'value',1,... 'tag','C',... 'position',[ ],... 'callback', function getC(calling_button, eventData) s = get(calling_button,'string'); set(calling_button,'value',str2double(s)); end

Radio Buttons Radio buttons are similar to checkboxes but designed to specify options that are mutually exclusive like in multiple-choice questions hToRadio1 = uicontrol('Style', 'radio',... 'Position',[ ],... 'String','Option1',... 'Callback', turnOffTheOtherButtons},... 'Value',1) Selected

Function turnOffTheOtherButtons h = findobj('Tag','option1'); set(h,'Value',0); : Do we need a different function for each button?

Step VIII – the radio buttons uicontrol('style','radio',... 'string','surf',... 'callback', 'tag','plot_type',... 'position',[ ],... 'value',1,... 'userdata',1); uicontrol('style','radio',... 'string','contour3',... 'callback', 'tag','plot_type',... 'position',[ ],... 'value',0,... 'userdata',0);

Step VIII – the radio buttons function plotTypeButtons(calling_button, eventData) handles = findobj('tag','plot_type'); set(handles,'value',0); set(calling_button,'value',1); end

Step IX - Now lets use it function run(main_axes, small_axes) onOff = findobj('tag','onOff'); speedSlider = findobj('tag','speedSlider'); C_window = findobj('tag','C'); close_button = findobj('tag','close'); type_handels = findobj('tag','plot_type');

Step IX - Now lets use it function run(main_axes, small_axes) onOff = findobj('tag','onOff'); speedSlider = findobj('tag','speedSlider'); C_window = findobj('tag','C'); close_button = findobj('tag','close'); type_handles = findobj('tag','plot_type'); How does type_handles differ from the other handles?

kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = ; end pause(0.1); end

kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = ; end pause(0.1); end

kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = ; end pause(0.1); end

kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = ; end pause(0.1); end

kill = get(close_button,'userData'); [x y] = meshgrid(-2:0.2:2); t = 0.001; while (~kill) on = get(onOff,'userData'); C = get(C_window,'value'); speed = get(speedSlider,'value'); kill = get(close_button,'userData'); activeB = findobj(type_handels,'value',1); plotType = get(activeB,'userdata'); if (on) draw(x,y,main_axes,small_axes,t,C,plot_type); t = t + speed; if (t >= 2*pi) t = ; end pause(0.1); end fig = findobj('tag','the_figure'); close(fig); end

cm = uimenu('tag','colorMap','label','Color Map'); Step XI – Adding color map menu

cm = uimenu('tag','colorMap','label','Color Map'); uimenu(cm, 'label','jet', uimenu(cm, 'label','hot', uimenu(cm, 'label','cool', Step XI – Adding color map menu function set_colorMap(calling_manu, eventData,colorMap) set(gcf,'colorMap',colorMap); parent = get(calling_manu,'parent'); all = get(parent,'children'); set(all,'checked','off'); set(calling_manu,'checked','on'); end

hToCheckBox = uicontrol('Style', 'checkbox',... 'Position',[ ],... 'String','Check Box example‘,... ‘Callback’,’’) Checkboxes allow the user to turn on/off a number of independent options Note: the position is measured in pixels from the left-bottom corner of the figure Checkboxes