Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Understanding Important Folders and Path Names in MATLAB

Important Folders MATLAB Uses

When you work with files and folders, be aware of key locations that MATLAB uses.

The Current Folder in MATLAB

matlabroot

matlabroot is the location where you installed . The location differs for each installation of MATLAB. Determine the location by running the matlabroot function.

Folders for MathWorks Products

Files and folders for products provided by The MathWorks are in matlabroot/toolbox:

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'))

Locations for Storing Your Files

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:

Path Names in MATLAB

When you work with files and folders, be aware of how MATLAB uses path names.

File Separator Characters, / and \

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.

Path Names on Different Platforms

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.

Spaces in Path Names

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 space

The command syntax does not work. For example:

delete my file.m   % Command syntax does NOT work for a file name containing a space

Absolute and Relative Path Names

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:

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:

Partial Path Names in MATLAB

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 enough of the path name to make the partial path name unique. Specifying the @ in method folder names is optional.

Maximum Length of Path Names in MATLAB

The maximum length allowed for a path name depends on your platform.

For example, on Microsoft Windows platforms:

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.

See Also


[1] UNIX is a registered trademark of The Open Group in the United States and other countries.

  


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