Exercise 4, Computer Science A321


Overview

Learn how to build a simple GUI in Matlab, using GUIDE if it helps (and it will). Do this for the cgview() function. Most of the material on this page is repeated/clarified in the README file.

cgview.m provides visualization of the convergence (or nonconvergence) of the conjugate gradient (CG) algorithm for solving linear systems A*x = b. You don't have to know anything about the CG method to create the GUI. But you'll find it helpful to look through the files in the order they are invoked.

In several places user input is needed, via the "input()" command. Replace some of those with GUI windows. Have the GUI initially display the default values, so that a user can just click some OK button or similar GUI widget. The defaults are in isempty() blocks right after each input() is requested.

New tools and ideas

Beyond writing a GUI, some minor new tricks used that you may not have seen before include:
  1. After calling pause() there is a drawnow command. If the user specified a pause time of 0, then cgview() won't show a movie, it will just draw the plot for the last iteration. The drawnow is not needed if pausetime > 0, but it doesn't hurt anything to have it there.
  2. Use of the view() and mesh() functions for 3D graphing.
  3. Using input() where the value needs to be a string. See if you can spot how I made that work so that a user only needs to type in a string without quote marks.

Code parameters to use

Almost no error checking is done, which is a big weakness that you do not need to address. But life will be easier if (when testing your GUI with non-default parameters) you make sure that n, maxits, tol are positive values and pausetime is nonnegative. matrixtype has only two possible options and both of them are strings. The goal here is not to bulletproof the code, just to practice with setting up a GUI. To make the write-execute-debug cycle faster, try the values

    15 <lt; n < 200
    4 < maxits < 1.2*n
    0 <= pausetime < 0.5

If you want to play around with it after setting up the GUI, have fun (e.g., fun might include trying n = 2000, maxits = 2*n, pausetime = 0). Just be aware that it will take a few seconds to run the numerical algorithm for large values of n.


Provided files

As usual, all of the files are in the single tar file ex4_files.tar so you don't have to download each file separately.


Steps and tasks

Steps to take: in general you create a design and layout for the GUI elements choosing whatever widgets are suitable for the values and actions needed. Matlab has a "layout editor" for this. It will create two files: a .m and .fig file. You program the actions that will be taken by writing "callbacks" using the m-file editor. GUIDE will create "stubs" for this in the m-file it generates, and they will have explicit comments saying something like 'insert here what actions the gui needs to take on a button press'.

For this assignment, the minimal expected is items 1 - 3 listed below, and using the easier alternative for the parameter variable 'power' in step 2. If you want more practice, you can do step 4 onwards, or any subset of those that you want to try.

  1. Create a GUI frame that requests the five variables
                n          (a positive integer)
                maxits     (a positive integer)
                tol        (a positive floating point number)
                pausetime  (a positive floating point number)
                matrixtype (one of two strings)
         
    matrixtype is one of the strings 'clump' or 'curve'. The code does no error-checking on the last item, so having the GUI provide only those two options will solve that problem. These inputs are roughly in lines 20-75 of drivecgview.m. Default values are in the code itself:
                n          = 100
                maxits     = 1.5*n
                tol        = 1.0e-8
                pausetime  = 0.1
                matrixtype = 'curve'
         
    The user will need some way of indicating when all of the parameters in the GUI are OK, so that the cgview() code can start. This will require a single callback being implemented by you.

  2. If matrixtype = 'curve' is chosen, the eigenvalues will follow y = xpower, where x is in the interval (0, 1]. Have another GUI window pop up in this case (i.e., if 'curve' is chosen), into which the user can enter the value of the variable power.

    Alternatively, if you find it easier have that GUI element be part of the frame from step 1. Filling in a value for power when 'clump' is specified won't have any effect and won't hurt anything. But if you use this alternative it'd be a bit more user-friendly if the choice of power was greyed-out (that is, non-settable) when 'clump' is specified.

  3. Save the GUI code. GUIDE will create two files for this, one with a .fig suffix, the other an m-file. Those are the two files needed, along with the modified m-files drivecgview.m, etc.

  4. For each GUI element you can provide a 'help' option. Put the comments that are currently in disp() statements into the corresponding help area.

  5. Freeze the animation when the user clicks in the figure window. Then start it up again on another mouse click.

  6. Use a slider so that pausetime can be modified dynamically, that is, while the animation is being shown.

  7. Create GUI elements for the other inputs

  8. Not a GUI item, but see if there's a better way to view the 3D plot. I used mesh(), but contour, surfl, and other options might be more illuminating.

Handin

Mail to a321@cs.indiana.edu all of the m-files, including any modifications you may have made to drivecgview.m, et al. Make sure you include the resultant .fig file(s), and the m-file that GUIDE generates and you modified.