| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → MATLAB |
| Contents | Index |
| Learn more about MATLAB |
| On this page… |
|---|
When you work with files and folders, be aware of key locations that MATLAB uses.
Is a reference location that MATLAB uses to find files.
Is not the same location as the operating system current folder.
Is sometimes referred to as the current directory, current working folder, or present working directory
matlabroot is the location where you installed . The location differs for each installation of MATLAB. Determine the location by running the matlabroot function.
Files and folders for products provided by The MathWorks are in matlabroot/toolbox:
Do not change files, folders, and subfolders in matlabroot/toolbox.
Do not store your files and folders in matlabroot/toolbox. The exception is the pathdef.m file, which you can change and save in its default location, matlabroot/toolbox/local.
To improve performance, at the beginning of each session, MATLAB loads and caches in memory the locations of files in matlabroot/toolbox. If you make changes to files and folders in matlabroot/toolbox, you can get unexpected results or see warnings related to the cache. See Toolbox Path Caching in the MATLAB Program.
To see a list of all toolbox folder names supplied with MathWorks products, run:
dir(fullfile(matlabroot, '/toolbox'))
For your convenience, MATLAB provides a MATLAB folder to store your files. At startup, MATLAB adds the folder to the search path, allowing MATLAB to access the files stored there.
The location of the MATLAB folder, referred to as the userpath, varies by platform and system configuration. To determine the location, run the userpath function.
On Microsoft Windows platforms, MATLAB sets the current folder to userpath at startup. On other platforms, instruct MATLAB to set the current folder to userpath at startup. For more information, see:
If you create subfolders within MATLAB, make the subfolders accessible to MATLAB.
If you store files in locations other than MATLAB:
Make the files accessible to MATLAB.
Do not store the files in the folders provided for MathWorks products.
When you work with files and folders, be aware of how MATLAB uses path names.
The file separator character is the symbol that distinguishes one folder level from another in a path name.
A forward slash (/) is a valid separator on any platform. A backward slash (\) is valid only on MicrosoftWindows platforms.
In the full path to a folder, the final slash is optional.
To use the file separator character when working with files programmatically, see filesep.
Use fullfile to construct path names in statements that work on all platforms. Use the ismac, ispc, and isunix functions when the path names differ depending on the platform.
When a function argument is a file or path name, and the name includes spaces, use the function syntax. For example:
delete('my file.m') % Function syntax works for a file name containing a spaceThe command syntax does not work. For example:
delete my file.m % Command syntax does NOT work for a file name containing a space
MATLAB always accepts absolute path names, also called full path names, such as I:/Document/My_Files. An absolute path name can start with any of the following:
UNC path '\\' string
Drive letter, on Microsoft Windows platforms
'/' character on UNIX[1] platforms
Some MATLAB functions also support relative path names. The reference page for a function specifies the valid types of path name. Unless otherwise noted, the path name is relative to the current folder. For example:
/myfolder refers to myfolder in the current folder and myfile.m refers to myfile.m in the current folder.
../myfolder/myfile.m refers to myfile.m in myfolder, where myfolder is at same level as the current folder. Each repetition of ../ moves up an additional folder level.
A partial path name is the last portion of a full path name for a location on the MATLAB search path.
Some functions accept partial path names. The reference page for a function typically specifies the valid types of path names.
Examples of partial path names are: matfun/trace, private/cancel, and demos/clown.mat.
Use a partial path name to:
Specify a location more conveniently than by using the full path name.
Specify a location independent of where MATLAB is installed.
Locate a function in a specific toolbox when there is more than one function with that name in multiple toolboxes. For example, get help for the set function in the Database Toolbox™ product:
help database/set
Locate private and method files, which sometimes are hidden.
Specify enough of the path name to make the partial path name unique. Specifying the @ in method folder names is optional.
The maximum length allowed for a path name depends on your platform.
For example, on Microsoft Windows platforms:
The maximum length is known as MAX_PATH.
You cannot use an absolute path name that exceeds 255 characters.
For a relative path name, you may need to use fewer than 255 characters. When the Windows operating system processes a relative path name, it can produce a longer absolute path name, and therefore exceed the maximum.
If you get unexpected results when working with long path names, use absolute instead of relative path names. Alternatively, use shorter names for folders and files.
ismac, ispc, and isunix functions, for MATLAB statements that require different path names for different platforms
[1] UNIX is a registered trademark of The Open Group in the United States and other countries.
![]() | How MATLAB Helps You Manage Files | Using the Current Folder Browser to Manage Files | ![]() |

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 |