MATLAB Function Reference | ![]() ![]() |
Standard dialog box for saving files
Syntax
uiputfile uiputfile('FilterSpec
') uiputfile('FilterSpec
','DialogTitle
') uiputfile('FilterSpec
','DialogTitle
',x,y) [FileName,PathName] = uiputfile(...) [FileName,PathName,FilterIndex] = uiputfile(...)
Description
uiputfile
displays a dialog box used to select a file for writing. The dialog box lists the files and directories in the current directory using the default
uiputfile('
displays a dialog box that contains a list of files in the current directory determined by FilterSpec
')
FilterSpec
.
FilterSpec
determines what files are displayed initialy in the dialog box. For example '*.m'
lists all MATLAB M-files.
If FilterSpec
is a cell array, the first column is used as the list of extensions, and the second column is used as the list of descriptions.
If FilterSpec
is not specified, uiputfile
uses the default list of file types (i.e., all MATLAB files).
FilterSpec
can also be a default file name, in which case, the file's extension is used as the default filter.
uiputfile('
displays a dialog box that has the title FilterSpec
','DialogTitle
')
DialogTitle
. To use the default file types and specify a dialog title, use:
uiputfile('
positions the dialog box at screen position [FilterSpec
','DialogTitle
',x,y)
x
,y
], where x
and y
are the distance in pixel units from the left and top edges of the screen. Note that positioning works only on UNIX platforms.
[FileName,PathName] = uiputfile(...)
returns the name and path of the file selected in the dialog box. If the user clicks the Cancel button, closes the dialog window, or if an error occurs, FileName
and PathName
are set to 0
.
[FileName,PathName,FilterIndex] = uiputfile(...)
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
.
Remarks
If you select a file that already exists, a prompt asks whether you want to overwrite the file. If you choose to, the function successfully returns but does not delete the existing file (which is the responsibility of the calling routines). If you select Cancel in response to the prompt, the function returns control back to the dialog box so you can enter another filename.
Examples
This statement displays a dialog box titled 'Save file name'
with the filename animinit.m
.
This statement displays a dialog box titled 'Save Workspace As'
with the filter specifier set to MAT-files.
You can specify a description of the file type in the FilterSpec
argument:
[filename, pathname, filterindex] = uiputfile( ... {'*.m;*.fig;*.mat;*.mdl','MATLAB Files (*.m,*.fig,*.mat,*.mdl)'; '*.m', 'M-files (*.m)'; ... '*.fig','Figures (*.fig)'; ... '*.mat','MAT-files (*.mat)'; ... '*.mdl','Models (*.mdl)'; ... '*.*', 'All Files (*.*)'}, ... 'Save as');
When you use multiple extensions with no descriptions, you must separate each with a semicolon:
Associate multiple extensions with one description like this:
[filename, pathname] = uiputfile({'*.m;*.fig;*.mat;*.mdl',... 'MATLAB Files (*.m,*.fig,*.mat,*.mdl)';'*.*',... 'All Files (*.*)'},'Save as');
See Also
![]() | uint8, uint16, uint32, uint64 | uiresume, uiwait | ![]() |