| 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… |
|---|
Files and Folders MATLAB Can Access |
For performance reasons, MATLAB limits where it looks for files. To run or get help for an M-file, or to load a MAT-file, the file must be in either:
The current folder in MATLAB
A folder that is on the search path. See What Is on the Search Path?
Also make accessible:
Folders containing files that you and others create.
Folders containing files that called by files you run.
Subfolders containing files you run. Making a folder accessible does not make its subfolders accessible
For files in private, @ (class), and + (package) folders, instead make the parent folder accessible. When the current folder is a private folder, subfolders and files in private are also accessible. See Organizing Classes in Directories.
For files that you and other users create, see Basic Options for Making Files Accessible.
To understand the differences in the basic options, and for other approaches, see All Options for Making Files Accessible.
Store the files you and other users create in the MATLAB folder, which is on the search path. See Locations for Storing Your Files.
Change the current folder to the folder that contains the files.
Add the folders that contain the files to the search path.
| Usage | Recommendation |
|---|---|
| You seldom run the file | Change the current folder to the folder that contains the file. See Determining and Changing the Current Folder. |
| The file is an M-file script (takes no input or output arguments) | Use the run function. |
| Files are in one folder | Put the files in the userpath folder. See Locations for Storing Your Files |
| Files are in multiple folders | Add the folders to the search path. See Adding Folders to the Search Path. If you regularly use the files, save the changes—see Saving Changes to the Search Path. |
Files call other files that are in multiple folders |
|
| Some files in multiple folders have the same name | See Detecting and Addressing Name Conflicts. |
| Use files in different versions of MATLAB or on different platforms | Modify the search path in a startup.m file. See Using the Search Path with Different MATLAB Installations. |
| Work with the search path content programmatically | See functions in the Search Path category. |
The following table lists ways to determine if MATLAB has access to a file.
| Option | When MATLAB Can Access the File | When MATLAB Cannot Access the File |
|---|---|---|
| Use the file. | Works successfully. | Produces an error. Typical error notifications include:
|
| View file in the Current Folder browser. | File is in the current folder. | File is in a subfolder of the current folder, unless the subfolder is on the search path. |
| Select File > Set Path. | Set Path dialog box list includes the file location. | List in the Set Path dialog box does not include the file location. |
| Run dir with no arguments. | Result includes the file, indicating file is in current folder. | Result does not include the file. |
| Runpath. | Result includes the file location, indicating file is in a folder on search path. | Result does not include the file location. |
| Run whichfileName. | Result is the full path to file. | Result is an error or a file with the same name in another location. |
When MATLAB has access to multiple files with the same name, these precedence rules determine the file MATLAB uses:
MATLAB uses the file in the current folder instead of a file on the search path.
MATLAB uses the file closest to the top of the search path instead of a file further down.
The file MATLAB does not use is called a shadowed file. In some cases, MATLAB warns you that a shadowed file exists.
To resolve other name conflicts, for example, when:
A file has the same name as a variable in the base workspace
A file has the same name as a built-in function for a MathWorks product
MATLAB follows these precedence rules:
Precedence Rules and File Precedence in the MATLAB Programming Tips documentation.
MATLAB might not be accessing the file you want it to when:
You use a file and get a warning about a potential name conflict.
You get unexpected results.
To identify a name conflict, try using the which function.
To address a name conflict, try one of the following:
Change the current folder.
Move or remove folders on the search path.
Rename or move files.
Specify the full path or partial path to the file you want.
Maintain a single version of a file instead of multiple versions.
Name conflicts can arise from using files that you create. They also can arise from using:
Files that other users create, such as from File Exchange
A different system that has additional MathWorks products installed
A different version of MATLAB, which could include new functions that have the same names as your existing files
![]() | Opening and Running Files Using the Current Folder Browser | Determining and Changing the Current Folder | ![]() |

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 |