MATLAB Function Reference Previous page   Next Page
uiputfile

Display standard dialog box for saving files

Syntax

Description

uiputfile displays a dialog box used to select a file for saving. The dialog box lists the files and directories in the current directory.

uiputfile('FilterSpec') displays a dialog box that lists files in the current directory. FilterSpec determines what files are displayed initially in the dialog box. For example '*.m' lists all MATLAB M-files.

If FilterSpec is a string or cell array, uiputfile appends 'All Files' to the list of file types. 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. 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, uiputfile uses the default list of file types (i.e., all MATLAB files).

uiputfile('FilterSpec','DialogTitle') displays a dialog box that has the title DialogTitle. To use the default file types and specify a dialog title, enter

uiputfile('FilterSpec','DialogTitle','DefaultName') 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 (\) separator.

uiputfile(...,'Location',[x y]) positions the dialog box at screen position [x,y], where x and y are the distances in pixel units from the left and top edges of the screen. This feature is supported 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 or closes the dialog window, 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 or closes the dialog window, FilterIndex is set to 0.

Remarks

If the user specifies or selects an existing filename, a warning message is displayed asking whether the user wants to overwrite the file. If the user selects Yes, the existing file is overwritten and uiputfile returns successfully. If the user selects No, control returns to the dialog. For a successful return, the specified filename must be valid.

Examples

Example 1. The following statement displays a dialog box titled 'Save file name' with the Filename field set to animinit.m and the filter set to M-files (*.m). Because FilterSpec is a string, the filter also includes All Files (*.*)

Example 2. The following statement displays a dialog box titled 'Save Workspace As' with the filter specifier set to MAT-files.

Example 3. To display several file types in the Save as type list box, separate each file extension with a semicolon, as in the following code. Note that uiputfile displays a default description for each known file type, such as "Simulink Models" for .mdl files.

Example 4. 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 5. The following code checks for the existence of the file and displays a message about the result of the open operation.

See Also

uigetfile


Previous page  Uipushtool Properties uiresume, uiwait Next page

© 1994-2005 The MathWorks, Inc.