User`s guide
10 Examples of GUIDE GUIs
Note Do not save GUI files to the examp les folder where you found them
or you will overwrite the original files. If you want to save G U I files, use
File > Save as from G UIDE, which saves both the GUI FIG-file and the
GUI code file.
Implement the List Box Directory GUI
The following sections describe the implementation:
• “Specify the Directory” on page 10-56 — shows how to pass a folder path as
input argument when the GUI runs.
• “Load the List Box” on page 10-57 — describes the subfunction that loads
the contents of the folder into the list box. This subfunction also saves
information about the contents of a folder in the
handles structure.
• “The List Box Callback” on page 10-58 — describes how the list box is
programmed to respond to user double clicks on items in the list box.
Specify the Directory
By default, GUI code files generated by GUIDE open the GUI when there are
no input arguments, and call a subfunction when the first input argument is a
character string. This example changes the behavior so that if you put the
example files,
lbox2.m and lbox2.fig,ontheMATLABpathyoucanrunthe
GUI displaying a particular folder. To do so, pass the
dir function as a string
for the first input argument, and a string that specifies the path to the folder
for the second input argument. For instance, from the Command W indow,
run the following to have the list box display the files in
C:\myfiles:
lbox2('dir','C:\my_files')
The following listing from lbox2.m shows the code for GUI initialization,
which sets the list box folder to:
• The current folder, if no folder is specified.
• The specified folder, if a folder is specified.
function lbox2_OpeningFcn (hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
10-56