MATLAB Function Reference    

Interactively retrieve a filename



uigetfile displays a dialog box used to retrieve a file. The dialog box lists the files and directories in the current directory.

uigetfile('FilterSpec') displays a dialog box that lists files in the current directory. FilterSpec determines the initial display of files and can be a full filename or include the * wildcard. For example, '*.m' lists all the MATLAB M-files. If FilterSpec is a cell array, the first column is use as the list of extensions, and the second column is used as the list of descriptions.

uigetfile('FilterSpec','DialogTitle') displays a dialog box that has the title DialogTitle.

uigetfile('FilterSpec','DialogTitle',x,y) positions the dialog box at position [x,y], where x and y are the distance in pixel units from the left and top edges of the screen. Note that some platforms may not support dialog box placement.

[FileName,PathName] = uigetfile(...) returns the name and path of the file selected in the dialog box. After you press the Done button, FileName contains the name of the file selected and PathName contains the name of the path selected. If you press the Cancel button or if an error occurs, FileName and PathName are set to 0.

[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, closes the dialog window, or if an error occurs, FilterIndex is se to 0.


If you select a file that does not exist, an error dialog appears. You can then enter another filename, or press the Cancel button.


This statement displays a dialog box that enables you 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 FileName and PathName. Note that uigetfile appends All Files(*.*) to the file types when FilterSpec is a string.

Use a cell array to specify a list of extensions and descriptions:

Separate multiple extensions with no descriptions with semi-colons.

Associate multiple extensions with one description using the first column in the cell array for the file extensions and the second column as the description:

This code checks for the existence of the file and returns a message about the success or failure of the open operation.

The exact appearance of the dialog box depends on your windowing system.

See Also

  uigetdir uiimport