Products & Services Solutions Academia Support User Community Company

Learn more about MATLAB   

Making Files and Folders Accessible to MATLAB

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:

Also make 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.

How to Make Files Accessible

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.

Basic Options for Making Files Accessible

All Options for Making Files Accessible

UsageRecommendation
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

  1. Determine the location of all the called files. See Displaying Dependencies Among M-Files.

  2. Add the folders to the search path. See Adding Folders to the Search Path.

Some files in multiple folders have the same nameSee Detecting and Addressing Name Conflicts.
Use files in different versions of MATLAB or on different platformsModify the search path in a startup.m file. See Using the Search Path with Different MATLAB Installations.
Work with the search path content programmaticallySee functions in the Search Path category.

Determining If MATLAB Can Access a File

The following table lists ways to determine if MATLAB has access to a file.

OptionWhen MATLAB Can Access the FileWhen MATLAB Cannot Access the File
Use the file.Works successfully.Produces an error. Typical error notifications include:
  • Dialog box

  • Message: ??? Undefined function or method 'file'Name' message

  • Message: Cannot find function 'fileName'

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.

Ensuring MATLAB Uses the File You Want

About Name Conflicts and Shadowed Files

When MATLAB has access to multiple files with the same name, these precedence rules determine the file MATLAB uses:

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:

MATLAB follows these precedence rules:

Detecting and Addressing Name Conflicts

MATLAB might not be accessing the file you want it to when:

To identify a name conflict, try using the which function.

To address a name conflict, try one of the following:

Name conflicts can arise from using files that you create. They also can arise from using:

See Also

  


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