Specifications

An Address Book Reader
5-33
GUI M-file options selected:
Generate callback function prototypes
Application allows only one instance to run
Calling the GUI
You can call the GUI M-file with no arguments, in which case the GUI uses the
default address book MAT-file, or you can specify an alternate MAT-file from
which the GUI reads information. In this example, the user calls the GUI with
a pair of arguments,
address_book('book', 'my_list.mat'). The first
argument,
'book', is a key word that the M-file looks for in the opening
function. If the M-file finds the key word, it knows tho use the second argument
as the MAT-file for the address book. Calling the GUI with this syntax is
analogous to calling it with a valid property-value pair, such as
('color',
'red')
. However, since 'book' is not a valid figure property, in this example
the opening function in the M-file includes code to recognize the pair
('book',
'my_list.mat')
.
Note that it is not necessary to use the key word
'book'. You could program
the M-file to accept just the MAT-file as an argument, using the syntax
address_book('my_list.mat'). The advantage of calling the GUI with the
pair
('book', 'my_list.mat') is that you can program the GUI to accept
other user arguments, as well as valid figure properties, using the
property-value pair syntax. The GUI can then identify which property the user
wants to specify from the property name.
The following code shows how to program the opening function to look for the
key word
'book', and if it finds the key word, to use the MAT-file specified by
the second argument as the list of contacts.
function address_book_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for address_book
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% User added code follows
if nargin < 4
% Load the default address book
Check_And_Load([],handles);
% If first element in varargin is 'book' and the second element is a
% MATLAB file, then load that file