tags:

views:

228

answers:

2
+5  Q: 

matlab search path

Hi,

I have some questions regarding the MATLAB Search Path.

(1) Current directory is in the search paths, but why it is not in the output of "path"? Where can I find the complete search paths?

(2) what are all possible ways to add search paths?

(3) Considering all 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.

Thanks!

+4  A: 

The best answer is to point you to the relevant MATLAB documentation:

Amro
+4  A: 

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:

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

  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

    • 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.

gnovice