Desktop Tools and Development Environment |
This section covers the following topics:
About 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. By default, the files supplied with MATLAB and MathWorks products are included in the search path. These are all of the directories and files under $matlabroot/toolbox
.
Any file you want to run in MATLAB must reside in a directory that is on the search path, or in the current directory. If you create any MATLAB related files, add the directories containing the files to the MATLAB search path. For instructions to view the search path and add directories to it, see Viewing and Setting the Search Path, including Caution Against Saving Files in $matlabroot/toolbox.
The search path is also referred to as the MATLAB path. Directories included are considered to be on the path. When you include a directory in 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.
Adding directories to the path is similar to performing an include or import in some other applications.
How the Search Path Determines Which Function to Use
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:
foo
as a variable.
foo.m
.
foo
as a built-in function, followed by foo.m
which is not built-in.
If there is more than one function with the same name, the order of directories on the path determines which of those functions MATLAB uses. When MATLAB looks for that function, it uses the first one found in the search path:
run
with the full pathname for the M-file. For example, use run d:/mymfiles/foo.m
to ensure that version of foo
runs.
which
for a specified function and MATLAB returns the full path to the function.
Although the actual search path rules are more complicated because of the restricted scope of private functions, subfunctions, object-oriented functions, P-files, and MAT-files, this simplified perspective is accurate for the ordinary M-files you usually work with. For more information, see Determining Which Function Is Called in the MATLAB Programming documentation.
Preferences for the Array Editor | How MATLAB Finds the Search Path, pathdef.m |
© 1994-2005 The MathWorks, Inc.