Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Creating, Changing, and Deleting Files and Folders

Creating Folders Using the Current Folder Browser

  1. Right-click at the location for the new folder. See Locations for Storing Your Files.

  2. From the context menu, select New Folder.

  3. Type the name for the new folder.

  4. Press Enter.

Creating Files Using the Current Folder Browser

Creating M-Files and Model Files

  1. Right-click at the location for the new file. See Locations for Storing Your Files.

  2. From the context menu, select New File.

  3. Select the type of file you want to create: Blank, Function, Class, or Model.

    The function or class M-file contains template information that prompts you to provide fundamental elements for the file.

  4. Type the name for the new file.

    For naming conventions, see Function Name and Naming M-files.

  5. Press Enter.

Creating and Updating MAT-Files

To create or update a MAT-file using variables in the workspace:

  1. In the Current Folder browser, change the current folder to the folder where you want to save the variables. See Locations for Storing Your Files.

  2. In the Workspace browser, select the variables to save.

  3. Drag the selected variables from the Workspace browser to the Current Folder browser.

  4. Drop the variables in the Current Folder browser:

    • Create a MAT-file by dropping the variables onto any empty location in the Current Folder browser. Then name the file.

    • Update an existing MAT-file by dropping the variables onto the file name.

      MATLAB warns you when the MAT-file contains variables of the same name. To update the existing variables, click Continue. Otherwise, click Cancel.

      To suppress the warning, select File > Preferences > General > Confirmation Dialogs, and clear the preference, Confirm when overwriting variables in MAT-files.

See also Opening Files and Importing Data Using the Current Folder Browser.

Creating Files and Folders Using Functions

To...Use This Function
Create a foldermkdir
Create an M-fileedit
Create a MAT-filesave

See also Locations for Storing Your Files.

Renaming Files and Folders Using the Current Folder Browser

  1. Select the item to rename.

  2. Right-click and select Rename from the context menu.

  3. Type over the existing name with the new name. Warnings appear when:

  4. Press Enter.

Renaming Files and Folders Using Functions

Use movefile.

Deleting Files and Folders Using the Current Folder Browser

To remove items:

  1. Select the items to delete.

    You cannot delete a folder while it is on the search path. See Making Changes to Folders on the Search Path.

  2. Right-click and select Delete from the context menu.

When you delete a file or folder using the Current Folder browser, MATLAB permanently removes it or moves it to another location, based on your platform.

PlatformBehavior Deleting Files and Folders Using the Current Folder Browser
Windows platforms

Follows the Windows system preference for sending files to the Recycle Bin. Some systems only allow recycling of local files and not files accessed on a network.

To delete a selection permanently when the system preference is set to recycle, press Shift+Delete.

Linux platformsSpecify the behavior:
  1. Select File > Preferences > General.

  2. Set the Deleting files option you want.

If you select to move files to a temporary folder, determine the location by running tempdir.

To delete a selection permanently when the preference is set to recycle, press Shift+Delete.

Macintosh platformsFollows your Macintosh system preference for sending files to the Trash.

Deleting Files and Folders Using Functions

To...Use This Function
Delete a filedelete
Delete a folderrmdir

There is no opportunity to recover folders deleted using rmdir.

By default, the delete function permanently deletes files. To move them to a different location instead, use the Deleting files preference:

  1. From any desktop tool, select File > Preferences > General.

  2. Set the Deleting files option you want.

With the preference set to delete files permanently, delete runs faster.

To override the preference when using the delete function, use the recycle function.

The location for deleted files varies by platform.

PlatformLocation for Files Not Permanently Deleted Using the delete Function
Windows platformsRecycle Bin. Some systems only allow recycling of local files and not files accessed on a network.
Linux platforms

MATLAB_Files_<day>-<mo>-<yr>_<hr>_<min>_<sec> folder in the location returned by the tempdir function.

For example, when tempdir returns /tmp, files deleted at 2:09:28 in the afternoon of November 9, 2009 move to /tmp/MATLAB_Files_09-Nov-2009_14_09_28.

Macintosh platformsTrash

Deleted files remain in these locations until you remove them. To remove deleted files, use operating system features, such as Empty Recycle Bin on Windows platforms.

Copying and Moving Files and Folders

Copy and move files and folders using the Current Folder browser using standard GUI practices. For example, drag a file from one folder to another or to another application, such as Windows Explorer.

Using the Current Folder browser, you cannot move a folder that is on the search path. See Making Changes to Folders on the Search Path

To copy and move files and folders using functions, use copyfile and movefile.

  


Recommended Products

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.

 © 1984-2009- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS