User`s guide
10 Examples of GUIDE GUIs
Save_Callback Code Listing
function Save_C allb ack(hObject, eventd ata, handles)
% Get the Tag of the menu selected
Tag = get(hObject, 'Tag');
% Get the address array
Addresses = handles.Addresses;
% Based on the item selecte d, take the appropr iate action
switch Tag
case 'Save'
% Save to the default addrboo k file
File = handles.LastFile;
save(File,'Addresses')
case 'Save_A s'
% Allow the user to select the file name to save to
[filename, path name ] = uiputfile( ...
{'*.mat';'*.*'}, ...
'Save as');
% If 'Cancel' was selected th en return
if isequal([fil enam e,pathname],[0,0])
return
else
% Construct the full path and save
File = fullfile(pathname,filename );
save(File,'Addresses')
handles.LastFile = File;
guidata(hObject, handles)
end
end
TheCreateNewMenu
The Create New menu clears the Contact Name and Contact Phone #
text fields to facilitate adding a new name and number. After making the new
entries, the user must then save the address book with the Save or Save As
menus. This callback sets the text
String properties to empty strings:
function New_Ca llba ck(hObject, eventda ta, handles)
set(handles.Contact_Name,'String',' ')
set(handles.Contact_Phone,'String', '')
10-94