MATLAB Creating Graphical User Interfaces

(Barry) #1

9 Examples of GUIDE UIs


end

if exist(file,'file') == 2
data = load(file);
end

% Validate the MAT-file
% The file is valid if the variable is called "Addresses"
% and it has fields called "Name" and "Phone"
flds = fieldnames(data);
if (length(flds) == 1) && (strcmp(flds{1},'Addresses'))
fields = fieldnames(data.Addresses);
if (length(fields) == 2) && (strcmp(fields{1},'Name'))...
&& (strcmp(fields{2},'Phone'))
pass = 1;
end
end

% If the file is valid, display it
if pass
% Add Addresses to the handles structure
handles.Addresses = data.Addresses;
% Display the first entry
set(handles.Contact_Name,'String',data.Addresses(1).Name)
set(handles.Contact_Phone,'String',data.Addresses(1).Phone)
% Set the index pointer to 1
handles.Index = 1;
% Save the modified handles structure
guidata(handles.Address_Book,handles)
else
errordlg('Not a valid Address Book','Address Book Error')
end

UI Behavior



  • “Open and Load MAT-File” on page 9- 11

  • “Retrieve and Store Data” on page 9- 11

  • “Data Update Confirmation” on page 9- 13

  • “Paging Through Entries — Prev/Next” on page 9- 14

  • “Save File” on page 9- 15

  • “Clear UI Fields” on page 9- 17

Free download pdf