Specifications
An Address Book Reader
5-43
catch
disp(lasterr);
end
end
Loading an Address Book Into the Reader
There are two ways in which an address book (i.e., a MAT-file) is loaded into
the GUI:
•When launching the GUI, you can specify a MAT-file as an argument. If you
do not specify an argument, the GUI loads the default address book
(
addrbook.mat).
•The user can select
Open under the File menu to browse for other MAT-files.
Validating the MAT-file
To be a valid address book, the MAT-file must contain a structure called
Addresses that has two fields called Name and Phone. The Check_And_Load
subfunction validates and loads the data with the following steps:
•Loads (
load) the specified file or the default if none is specified.
•Determines if the MAT-file is a valid address book.
•Displays the data if it is valid. If it is not valid, displays an error dialog
(
errordlg).
•Returns
1 for valid MAT-files and 0 if invalid (used by the Open menu
callback)
•Saves the following items in the
handles structure:
–The name of the MAT-file
–The
Addresses structure
–An index pointer indicating which name and phone number are currently
displayed
Check_And_Load Code Listing
This is the Check_And_Load function.
function pass = Check_And_Load(file,handles)
% Initialize the variable "pass" to determine if this is a valid file.
pass = 0;