Main Content

edit

Edit or create file

Description

edit opens a new file called Untitled.m in the Editor. MATLAB® does not automatically save Untitled.m.

example

edit file opens the specified file in the Editor. If file does not already exist, MATLAB asks if you want to create it. You must have write permission to the path to create file. Otherwise, MATLAB ignores the argument.

Editing MAT-files and binary files such as P-code files and MEX-files is not supported using the edit function.

example

edit file1 ... fileN opens each file, file1 ... fileN, in the Editor.

example

Examples

collapse all

Create and open a new file titled Untitled.m in the MATLAB® Editor (or default editor). Untitled.m does not appear in your Current Folder.

edit

Create two new files in a new folder.

Create a file in a new directory using a character vector. A dialog box appears, asking if you want to create new_script.m. Click Yes to create and open tests/new_script.m.

mkdir tests
edit tests/new_script.m

Create a second file using a string. Click Yes to create and open tests/new_script2.m.

S = "tests/new_script2.m";
edit(S)

Create and open the files file1, file2, file3, and file4 in sequence.

edit file1 file2 file3 file4

Input Arguments

collapse all

File name, specified as a character vector or string.

file can include a partial path, complete path, relative path, or no path. If file includes a partial path or no path, edit looks for the file on the search path. If file specifies a path that contains a nonexistent folder, MATLAB throws an error.

If you do not specify the extension and MATLAB is unable to find file, then edit creates a file with the specified name and a .m extension. You must specify the extension to open .mdl files.

If file appears in multiple locations on the MATLAB search path, edit opens the first instance of file found on the path. The other instances of file are considered shadowed. To edit a shadowed instance of file, include the partial path to file.

Example: edit folderName/file

If file is defined in a package, to explicitly refer to that file, include the package identifier. For more information about specifying a package identifier, see Distinguish Between Packages Using Package Identifiers.

Example: edit packageName@1.0.1/file

If the file is part of a class or namespace, then either specify the path and extension or separate the components of the name with periods.

Example:edit className.name

Example:edit namespaceName.name

Example:edit namespaceName.className.name

Example:edit namespaceName.name

Data Types: char | string

File names, specified as a list of character vectors or strings separated by spaces. For more information about specifying files, see file.

Example: edit myscript1.m myscript2.mlx myfunction.m

Version History

Introduced before R2006a