MATLAB SIMULINK 7 - GRAPHICAL USER INTERFACE Manual de usuario Pagina 260

  • Descarga
  • Añadir a mis manuales
  • Imprimir
  • Pagina
    / 330
  • Tabla de contenidos
  • MARCADORES
  • Valorado. / 5. Basado en revisión del cliente
Vista de pagina 259
10 Examples of GUIDE GUIs
10-36
Check_And_Load Code Listing
This is the Check_And_Load function.
function pass = Check_And_Load(file,handles)
% Initialize the variable "pass" to determine if this is a valid
% file.
pass = 0;
% If called without any file then set file to the default
% filename.
% Otherwise, if the file exists then load it.
if isempty(file)
file = 'addrbook.mat';
handles.LastFile = file;
guidata(handles.Address_Book,handles)
end
if exist(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;
guidata(handles.Address_Book,handles)
% 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 and save handles
handles.Index = 1;
Vista de pagina 259
1 2 ... 255 256 257 258 259 260 261 262 263 264 265 ... 329 330

Comentarios a estos manuales

Sin comentarios