9 Examples of GUIDE UIs
- If you create a new entry, you must save the MAT-file using the File > Save menu.
The Contact_Name_Callback callback uses the handles structure to access the
contents of the address book and to maintain an index pointer (handles.Index)
that enables the callback to determine what name is displayed before you enter
a new one. The index pointer indicates what name is currently displayed. The
Check_And_Load function adds the address book and index pointer fields when you run
the address_book function.
If you add a new entry, the callback adds the new name to the address book and updates
the index pointer to reflect the new value displayed. The updated address book and index
pointer are again saved (using guidata) in the handles structure.
Contact_Name_Callback
function Contact_Name_Callback(hObject, eventdata, handles, varargin)
% Get the strings in the Contact Name and Phone text box
Current_Name = get(handles.Contact_Name,'string');
Current_Phone = get(handles.Contact_Phone,'string');
% If empty then return
if isempty(Current_Name)
return
end
% Get the current list of addresses from the handles structure
Addresses = handles.Addresses;
% Go through the list of contacts
% Determine if the current name matches an existing name
for i = 1:length(Addresses)
if strcmp(Addresses(i).Name,Current_Name)
set(handles.Contact_Name,'string',Addresses(i).Name)
set(handles.Contact_Phone,'string',Addresses(i).Phone)
handles.Index = i;
guidata(hObject,handles)
return
end
end
% If it's a new name, ask to create a new entry
Answer=questdlg('Do you want to create a new entry?', ...
'Create New Entry', ...
'Yes','Cancel','Yes');