Creating Graphical User Interfaces |
Running the GUI
The GUI is nonblocking and nonmodal since it is designed to be displayed while you perform other MATLAB tasks.
GUI Option Settings
This GUI uses the following GUI option settings:
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
elseif (length(varargin) == 2 & strcmpi(varargin{1},'book') & (2 == exist(varargin{2},'file'))) Check_And_Load(varargin{2},handles); else errordlg('File Not Found','File Load Error') set(handles.Contact_Name,'String','') set(handles.Contact_Phone,'String','') end
An Address Book Reader | Loading an Address Book Into the Reader |
© 1994-2005 The MathWorks, Inc.