Lab 25

Dialog Boxes

CS211 Lab Policy:

Instructions:

For this lab assignment you are asked to manipulate the same NCAA Basketball statistics data files you used for Lab 25. You should already have the data files on your computer's hard drive. If not, download the file NCAA Basketball Stats.zip and save it in a new empty folder in your MATLAB working directory. Save your Lab25.m file to the same folder as the statistics data files.

The overall intent of this lab assignment is to search the NCAA Basketball statistics data files for team rankings, but let the user select which statistic files to search and which team name to search for.

To investigate the use of dialog boxes, implement MATLAB code that performs the following tasks.
  1. Use a uigetfile() function to get a data file name from the user. Use a 'file specification filter' of '*.txt' since all the statistic files are text files. This reduces the number of files that the user initially can choose from, which typically makes the program easier to use for the user. Make sure you capture both return values from the function, i.e., the file name the user selected and the folder the file is in.
     
  2. After the call to uigetfile(), perform a validation to make sure a valid file name was selected by the user. If the user selects the "Cancel" button in the dialog box, the uigetfile() function returns a "file_name" value of 0. If the user selects "Cancel," then display a message box using the msgbox() function stating that the program is terminating and then return from the Lab25 function (your instructor may offer a different approach since using return violates some principles of good programming practice).

    If the user selected a file, create a "fully qualified file name" by creating a string that contains the folder name and file name in a single string. For example, if the file name is 'Fred.txt' and the folder name is 'C:\Documents and Settings\Fred.Smith\My Documents\', then the fully qualified name would be 'C:\Documents and Settings\Fred.Smith\My Documents\Fred.txt'. Display the fully qualified file name to the command window.
     
  3. Execute your program and attempt to select more than one file name in the dialog box. It's not possible -- right?. To overcome this you can add arguments to the call to uigetfile() that allows a user to select multiple files. To discover how to do this, look up the help documentation on the uigetfile() function in the MATLAB help system. Then modify your call to the uigetfile() function in step 1 to allow a user to select multiple files from the GUI dialog box.

    Now the 'file_name' returned by the uigetfile() function can be one of three values:
    1. A cell array of strings - which means the user selected multiple file names.
    2. A character array (string) - which means the user selected a single file name.
    3. A double zero - which means the user selected the cancel button.

    You can use the iscell() function and/or the ischar() function to test the return value to determine it's data type. If the user selected multiple files, create a cell array of 'fully qualified file names.' If the user selected a single file, create a cell array that points to one 'fully qualified file name.' If the user selected the 'Cancel' button, display a message box using the msgbox() function and return.
     

  4. Use a inputdlg() function call to get a Basketball team name from the user. Make the default team name displayed in the dialog box be 'Air Force'.
     
  5. Copy and paste your code from step 3 of Lab 24 at this point in your Lab 25 code. (This code should search all statistic files for matching teams.) Then modify the code to search for the team name that the user entered in step 4 from the files selected by the user in step 3. (Make sure your code works correctly if the user selects only 1 file in step 3.)
     
  6. Now use a uiputfile() function call to get a file name from the user. This file name will be used to save the results from step 5 to a text file. Perform the same validation operations as steps 1, 2 & 3 (i.e., display a message box using msgbox() and exit if the user selects the cancel button; or display the fully qualified file name entered by the user).
     
  7. Save the results of the search in step 5 to a text file. You will have to modify the code in step 5 to remember the rankings and statistic categories that were matched.

To accomplish this lab assignment you used 4 different GUI dialog box functions (uigetfile(), msgbox(), inputdlg(), and uiputfile()) . The use of GUI dialog boxes typically makes a program more "user friendly." Please make sure you understand how to use all of the GUI dialog box functions described in the lesson notes.

Turn-in:

Submit your Lab25.m file.