Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use the MATLAB search path

I have some questions regarding the MATLAB Search Path:

  1. The current directory is on the search path, but why is it not in the output of "path"? Where can I find the complete search path?

  2. What are all the possible ways to add search paths?

  3. Considering all the possible ways to add search paths (e.g. pathdef.m, startup.m, MATLABPATH env variable, etc), what is the order of the search paths added? I think it is important because when files with same name exist in different search paths, the one on the top will be picked.

like image 614
Tim Avatar asked Jan 25 '10 01:01

Tim


People also ask

What is the MATLAB search path?

The search path, or path is a subset of all the folders in the file system that MATLAB uses to locate files efficiently. Change Folders on Search Path. Interactively add and remove folders, and change the order of folders on the search path, for the current MATLAB session and for future MATLAB sessions.

What is search path?

A search path is a basic expression in IBM® Cognos® that allows you to find objects. It is one of the parameters that you need for performing operations on reports using commands. You can use the search path to find one particular object or a set of objects within a folder using an asterisk * as a wildcard character.

How do I change the path in MATLAB?

MATLAB's path can be changed using the "Set Path" button in the toolbar. Alternatively, run the command "pathtool" in MATLAB. Functionality such as adding individual folder, adding folders with subfolders, removing folders, and arranging the search path is available in the path tool.


1 Answers

The links provided by Amro should be quite helpful in answering your questions. To address them more specifically:

  1. The output from PATH will show the contents of the pathdef.m file, which should include all of the following:

    • Folders provided with MATLAB and other MathWorks products (i.e. toolboxes). These folders are located in the root MATLAB folder, which you can find using the MATLABROOT function.

    • The MATLAB user folder (i.e. My Documents\MATLAB on Windows platforms), which can be found using the USERPATH function.

    • Any other folders the user(s) has added to the path file.

    The complete search path contains the above, plus whatever the current directory is. The current directory isn't saved as part of the path file since it can be changed during the MATLAB session. You can find the current folder using the PWD function.

  2. The search path can be changed by changing either the path file or the current directory. You can modify the path file in the following ways:

    • Using the PATH function, along with the other associated functions ADDPATH, RMPATH, and SAVEPATH.

    • Using the Set Path dialog box, which can be opened from the Command Window by selecting File > Set Path or by calling the function PATHTOOL.

    • Modifying the startup.m file.

    And the current directory can be changed in the following ways:

    • Using the CD function.

    • Using the Current Folder Browser.

  3. When you modify the path file using the above methods, new folders are typically added to the top of the path list. You can change the order of the paths in the path file using the Set Path dialog box.

    When there are functions that share the same name, MATLAB follows the following function precedence order to determine which function to use:

    • Variable (if a variable shares the same name as a function)

    • Nested function

    • Subfunction

    • Private function

    • Class constructor

    • Overloaded method

    • Function in the current directory

    • Function elsewhere on the search path

    Note that a function in the current directory is called before one elsewhere on the search path. Also, files closest to the top of the search path have precedence over files further down.

like image 61
gnovice Avatar answered Oct 17 '22 20:10

gnovice