Specifications
5 GUI Applications
5-10
Note The following links execute MATLAB commands and are designed to
work within the MATLAB Help browser. If you are reading this online or in
PDF, you should go to the corresponding section in the MATLAB Help
Browser to use the links.
• Click here to display this GUI in the Layout Editor.
• Click here to display the GUI M-file in the editor.
Implementing the GUI
The following sections describe the implementation:
• “Specifying the Directory to List” — shows how to pass a directory path as
input argument when the GUI is run.
• “Loading the List Box” — describes the subfunction that loads the contents
of the directory into the list box. This subfunction also saves information
about the contents of a directory in the
handles structure.
• “The List Box Callback” — explains how the list box is programmed to
respond to user double clicks on items in the list box.
Specifying the Directory to List
You can specify the directory to list when the GUI is first opened by passing the
string
'create' and a string containing the full path to the directory as
arguments. The syntax for doing this is
list_box('create','dir_path'). If
you do not specify a directory (i.e., if you call the GUI M-file with no input
arguments), the GUI then uses the MATLAB current directory.
The default behavior of the GUI M-file that GUIDE generates is to run the GUI
when there are no input arguments or to call a subfunction when the first input
argument is a character string. This example changes this behavior so that you
can call the M-file with
• No input arguments — run the GUI using the MATLAB current directory.
• First input argument is
'create' and second input argument is a string that
specifies a valid path to a directory — run the GUI, displaying the specified
directory.