문제

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.

도움이 되었습니까?

해결책

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

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top