|MATLAB Function Reference|
Display standard dialog box for retrieving files
uigetfile displays a dialog box used to retrieve one or more files. The dialog box lists the files and directories in the current directory.
uigetfile(' displays a dialog box that lists files in the current directory.
FilterSpec determines the initial display of files and can include the
* wildcard. For example,
.m' lists all the MATLAB M-files.
FilterSpec is a string or cell array,
'All Files' to the list of file types. If
FilterSpec is a cell array, the first column contains the list of extensions, and the second column contains the list of descriptions.
FilterSpec can also be a filename. In this case the filename becomes the default filename and the file's extension is used as the default filter. If
FilterSpec is not specified,
uigetfile uses the default list of file types (i.e., all MATLAB files).
displays a dialog box that has the title
displays a dialog box in which a specified string, in this case
'DefaultName', appears in the File name field.
'Default Name' can be a filename or the name of a directory. If it is the name of a directory, you must follow it with a slash
(/) or backslash
positions the dialog box at position
y are the distances in pixel units from the left and top edges of the screen. This feature is supported only on UNIX platforms.
specifies if multiple file selection is enabled for the
uigetfile dialog. Valid values for
'off'(default). If the value of
'on' and the user selects more than one file in the dialog box, then
FileName is a cell array of strings, each of which represents the name of a selected file. Otherwise,
Filename is a string representing the selected filename. Because multiple selections are always in the same directory,
PathName is always a string that represents a single directory.
[FileName,PathName] = uigetfile(...)
returns the name and path of the file selected in the dialog box. After the user clicks the Done button,
FileName contains the name of the file selected and
PathName contains the name of the path selected. If the user clicks the Cancel button or closes the dialog window,
PathName are set to
[FileName,PathName,FilterIndex] = uigetfile(...)
returns the index of the filter selected in the dialog box. The indexing starts at 1. If the user clicks the Cancel button or closes the dialog window,
FilterIndex is set to
A successful return occurs only if all the selected files exist. If the user selects a file that does not exist, an error message is displayed and control returns to the dialog box.
Example 1. The following statement displays a dialog box that enables the user to retrieve a file. The statement lists all MATLAB M-files within a selected directory. The name and path of the selected file are returned in
PathName. Note that
All Files(*.*) to the file types when
FilterSpec is a string.
The dialog box is shown in the following figure.
Example 2. To create a list of file types that appears in the Files of type list box, separate the file extensions with semicolons, as in the following code. Note that
uigetfile displays a default description for each known file type, such as "Simulink Models" for
Example 3. If you want to create a list of file types and give them descriptions that are different from the defaults, use a cell array, as in the following code. This example also associates multiple file types with the
'MATLAB Files' description.
The first column of the cell array contains the file extensions, while the second contains the descriptions you want to provide for the the file types. Note that the first entry of column one contains several extensions, separated by semicolons, all of which are associated with the description
'MATLAB Files (*.m,*.fig,*.mat,*.mdl)'. The code produces the dialog box shown in the following figure.
Example 4. The following code checks for the existence of the file and displays a message about the result of the open operation.
Example 5. This example creates a list of file types and gives them descriptions that are different from the defaults, then enables multiple file selection. The user can select multiple files by holding down the Shift or Ctrl key and clicking on a file.
© 1994-2005 The MathWorks, Inc.