9 Examples of GUIDE UIs
the Contact_Name_Callback or the Contact_Phone_Callback updates
handles.Addresses.
If you select Save, the save function is called to save the current MAT-file with the new
names and phone numbers.
If you select Save As, a dialog box displays which enables you to select the name of an
existing MAT-file or specify a new file. The dialog box returns the selected file name and
path. The final steps include:
- Using fullfile to create a platform-independent path name.
- Calling save to save the new data in the MAT-file.
- Updating the handles structure to contain the new MAT-file name.
- Calling guidata to save the handles structure.
Save_Callback
function Save_Callback(hObject, eventdata, handles, varargin)
% Get the Tag of the menu selected
Tag = get(hObject,'Tag');
% Get the address array
Addresses = handles.Addresses;
% Based on the item selected, take the appropriate action
switch Tag
case 'Save'
% Save to the default addrbook file
File = handles.LastFile;
save(File,'Addresses')
case 'Save_As'
% Allow the user to select the file name to save to
[filename, pathname] = uiputfile( ...
{'*.mat';'*.*'}, ...
'Save as');
% If 'Cancel' was selected then return
if isequal([filename,pathname],[0,0])
return
else
% Construct the full path and save
File = fullfile(pathname,filename);
save(File,'Addresses')
handles.LastFile = File;