Lab 26

Handle Graphics

CS211 Lab Policy:

Instructions:

For this lab you will create and submit the program Lab26() saved in the file lab26.m.  Add code to your lab26 program that does the following tasks.

  1. Clear the command window.
     
  2. Plot sin(x) and cos(x) on the interval x = -2π to 2π.  (Use hold('on') and 2 calls to the plot() function.) Capture the graphics handle returned by each call to the plot() function for each graphed line. These will be handles to line objects.
     
  3. Use the get() function to get a handle to the axes object the lines are graphed in. (Use the parent property of either line.)
     
  4. Get and display all of the properties of an axes object. (Use the get() command and display your results using disp().) Examine the structure array that contains the properties. Note that there are many properties of an axes object!
     
  5. Get and display all of the properties of a line object.  (Use the get() command.) Notice that line objects have different properties as compared to axes objects.
     
  6. In order to see the individual changes to your graph requested in the following tasks, place a waitforbuttonpress() function after each one. This will pause your program until the user clicks a mouse button or presses a key on the keyboard. Add a close() command at the bottom of your Lab26() function  so that each time you run your program you will start with a new graph.
     
    1. Change the line object that graphs the sine curve to a red line of width 3. (Change the 'color' and 'lineWidth' properties. For the color, you can use the predefined color name 'red' or a (red, green, blue) vector, [1 0 0]).
       
    2. Change the line graph of the cosine curve to a green line of width 4. (For the color, you can use the predefined color name 'green' or a (red, green, blue) vector, [0 1 0]).
       
    3. Add vertical grid lines to the plot. (Use the 'xgrid' property of the axes object. Its value can be 'on' or 'off'.)
       
    4. Add horizontal grid lines to the plot. (Use the 'ygrid' property of the axes object. Its value can be 'on' or 'off'.)
       
    5. Get the handle for the figure object that contains the axes object. (Use the 'parent' property of the axes object.) Then remove the figure number in the title bar and change the figure name to "Sine and Cosine." In addition, change the figure background color to purple ([1 0 1]). (Use the 'numberTitle', 'name', and 'color' properties of the figure object.)
       
    6. Close the figure.

Please spend your remaining lab time working on PEX 3.

Turn-in:

Submit your Lab26.m file.