
10 Examples of GUIDE GUIs
10-14
• If the selection is a file — get the file extension (fileparts) to determine if
it is a FIG-file, which is opened with
guide. All other file types are passed to
open.
The
open statement is called within a try/catch block to capture errors in an
error dialog (
errordlg), instead of returning to the command line.
get(handles.figure1,'SelectionType');
% If double click
if strcmp(get(handles.figure1,'SelectionType'),'open')
index_selected = get(handles.listbox1,'Value');
file_list = get(handles.listbox1,'String');
% Item selected in list box
filename = file_list{index_selected};
% If directory
if handles.is_dir(handles.sorted_index(index_selected))
cd (filename)
% Load list box with new directory.
load_listbox(pwd,handles)
else
[path,name,ext,ver] = fileparts(filename);
switch ext
case '.fig'
% Open FIG-file with guide command.
guide (filename)
otherwise
try
% Use open for other file types.
open(filename)
catch
errordlg(lasterr,'File Type Error','modal')
end
end
end
end
Opening Unknown File Types
You can extend the file types that the open command recognizes to include any
file having a three-character extension. You do this by creating an M-file with
the name
openxyz, where xyz is the extension. Note that the list box callback
Commentaires sur ces manuels