Lab 30
GUI Components
CS211 Lab Policy:
- This lab exercise will not be graded.
- Submit as much as you have completed before the end of the lab period in
which it is assigned.
- If you do not finish this lab work, it is to your advantage to finish it
outside of class. Please re-submit your finished work to the course web
site.
- You may receive help from anyone in completing this lab.
- You may not submit another student's code as part of your
lab.
Instructions:
For this assignment you will create a GUI program,
Lab30.m, that allows a user to
investigate the curve cos(x+A) + sin(B*x)
as A varies from
[0, 2pi] and B
varies from [-10, +10]. The curve should
be plotted in the x-range [-10, +10]. Your interface should include the
following components:
- A static text component that
shows the current equation (with appropriate values for A and B filled in).
- An axes component that plots the
curve.
- Two slider bars that allow the
user to vary the values of A and B. The slider bars should be labeled with
appropriate static text components.
An example program GUI is shown in the figure below.

Helpful suggestions:
- Make sure you give each component a descriptive
Tag property so that its callback function and object handle
will have a meaning name.
- Make sure you set the Units
property of all components to 'normalized'.
- Each time you change the value of A or B the curve will change. The
default behavior for MATLAB is to adjust the y-axis limits based on the
current curve's y-values. This makes it difficult to visualize the changes
to the curve as A and B change. You need to hold the y-axis constant as the
curve changes. To do this, set the 'YLim'
property for the axes component to [-2 2]
every time you plot the curve.
- Set initial default values for A and B in your
*_OpeningFcn()
function. In addition, plot the initial view of the curve and update the
title.
- Each time a slider bar changes, your code needs to redraw the curve
appropriately.
- Since the *_OpeningFcn()
function and both the slider bars must do the same work, consider
creating a single function to perform the work of updating the window. Then
you can call this function from the *_OpeningFcn()
function and the slider callback functions.
Turn-in:
Submit your
Lab30.m
and
Lab30.fig file.