Specifications
List Box Directory Reader
5-11
• First input argument is not a directory, but is a character string and there is
more than one argument — execute the subfunction identified by the
argument (execute callback).
The following code listing show the setup section of the GUI M-file, which does
one the following:
• Sets the list box directory to the current directory, if no directory is specified.
• Changes the current directory, if a directory is specified.
function lbox2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to untitled (see VARARGIN)
% Choose default command line output for lbox2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
if nargin == 3,
initial_dir = pwd;
elseif nargin == 4 & exist(varargin{1},'dir')
initial_dir = varargin{1};
else
errordlg('Input argument must be a valid directory','Input
Argument Error!')
return
end
% Populate the listbox
load_listbox(initial_dir,handles)
Loading the List Box
This example creates a subfunction to load items into the list box. This
subfunction accepts the path to a directory and the
handles structure as input
arguments. It performs these steps: