This section covers the following topics:
Purpose of the Search Path
MATLAB uses a search path to find M-files and other MATLAB related files, which are organized in directories on your file system. These files and directories are provided with MATLAB and associated toolboxes. Any file you want to run in MATLAB must reside in a directory that is on the search path or in the current directory. By default, the files supplied with MATLAB and MathWorks toolboxes are included in the search path.
If you create any MATLAB related files, add the directories containing the files to the MATLAB search path. For instructions to view and modify the search path, see Viewing and Setting the Search Path.
Save any M-files you create and any MathWorks-supplied M-files that you edit in a directory that is not in the $|
How the Search Path Works
The search path is also referred to as the MATLAB path. Files included are considered to be on the path. When you include a directory on the search path, you add it to the path. Subdirectories must be explicitly added to the path; they are not on the path just because their parent directories are. The search path is stored in the file
The order of directories on the path is relevant. MATLAB looks for a named element, for example,
foo, as described here. If you enter
foo at the MATLAB prompt, MATLAB performs the following actions:
fooas a variable.
fooas a built-in function.
Although the actual search rules are more complicated because of the restricted scope of private functions, subfunctions, and object-oriented functions, this simplified perspective is accurate for the ordinary M-files you usually work with.
The order of the directories on the search path is important if there is more than one function with the same name. When MATLAB looks for that function, only the first one in the search path order is found. Other functions with the same name are considered to be shadowed and cannot be executed. For more information, see How MATLAB Determines Which Method to Call in Programming and Data Types.
To see the pathname used, use
which for a specified function. For more information, see the reference page for
You can use a different
pathdef.m if you store it in your startup directory--see Startup Directory for MATLAB.
|Preferences for the Array Editor||Viewing and Setting the Search Path|