Docsity

Graphical User Interfaces in Scientific Computing: Handling Objects and Customizing Plots, Exams of Computer Science

Partial preview of the text

Download Graphical User Interfaces in Scientific Computing: Handling Objects and Customizing Plots and more Exams Computer Science in PDF only on Docsity!

Introduction to

Scientific Computing and

Problem Solving

Lecture # 16

Graphical User Interfaces

(GUIs)

Announcements

  • [Announcements of the day]
  • By now you have completed the midterm exam
    • Well done! Congratulations!
  • What’s next: we switch to C after this lecture
    • 4 weeks of classes
    • 4 labs, 3 homeworks, 1 project, 1 final exam
  • Final exam
    • Not cumulative, covering only C material

Handle Graphics

  • Functions that control the characteristics of

graphics objects produced by MATLAB

  • Permits fine adjustments to appearance
    • X-axis grid only
    • Orange line color
  • Enables the creation of graphical user

interfaces (GUI)

Root (computer screen)

Figure Figure

GUI

objects

Axes

Parent

Children

Image Line Text Surface Rectangle Light

Figure

Axes

…

… …

MATLAB Graphics System

Example 15-

Customizing a Plot

  • Plot the function from - 3!! x! 3! then
    • Make the background pink
    • Show the y-axis grid lines only
    • Change the line to orange and 2-points wide

sin

sinc

x

x

x

x

x

m-files: Ex 15 _ 1

User-Defined Data

  • Additional data can be defined and stored

with any object

setappdata(hndl, 'DataName', DataValue)

value = getappdata(hndl, 'DataName')

struct = getappdata(hndl)

hndl : object handle

DataName : name of the data

DataValue : value assigned to the name

value : value assigned to the name

struct : all user-defined names and values

Example 15-

Selecting Objects

  • Write a program that displays information

about selected objects in a plot until a key is

pressed

m-files: Ex 15 _ 2

Position

  • Many objects have a Position property,

which specifies size and position on the screen

  • The Units property can be pixels (default),

inches, centimeters, points, characters, or

normalized

  • Normalized coordinates use ( 0 , 0 ) for lower-

left and ( 1 , 1 ) for upper-right corners

  • Figure objects

[left bottom width height]

m-files: lect 15 _ 2

Example 15-

Positioning Objects

  • The program creates two overlapping sets of

axes with a single figure

  • The first has a text comment attached to the

line itself

  • The second has a text comment in the lower

left corner

m-files: Ex 15 _ 3

Example 15-

Animating Plots

  • Fine control over plotting allows a form of

animation

m-files: Ex 15 _ 4

GUI Elements

  • Components
    • Pushbuttons, labels, boxes, menus, sliders, axes, etc.
    • Commands uicontrol, uimenu, uicontextmenu,

uitoolbar, axes

  • Containers
    • Hold components
    • Figure, panel, button group
    • Commands figure, uipanel, uibuttongroup
  • Callbacks
    • Code executed as a response to an event
    • Needed for every GUI component with a function

Example 16-

Getting the Time

  1. Run GUIDE (Graphical User Interface

Development Environment)

  1. Select push button tool and locate

  2. Using Property Inspector, change String

property to "Time"

  1. Save as time.fig

  2. Add callback function code

Gallery of GUI Components

  • Static text fields
  • Edit boxes
  • Pushbuttons
  • Toggle buttons
  • Checkboxes and radio buttons
  • Popup menus
  • List boxes
  • Sliders

m-files: editbox, togglebutton, checkbox, radiobutton, popupmenu, listbox

Example 16-

Temperature Conversion

  1. Layout 2 text fields, 2 edit boxes, and one slider
  2. Set Tag properties: Label1 , Label2 , Edit1 , Edit2 ,

and Slider

  1. Store String property values "Degrees F" and

Degrees C"

  1. Set slider maximum to 100
  2. Store initial values in String property for edit fields

and Value property for slider (32°F and 0°C)

  1. Set Name property of figure to 'Temperature

Conversion '

  1. Save as temp_conversion.fig

temp_conversion.fig