如何使用MATLAB搜索路径 [英] How to use the MATLAB search path

查看:558
本文介绍了如何使用MATLAB搜索路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些有关MATLAB搜索路径的问题:


  1. 当前目录位于搜索路径上,但为什么它不在输出的路径?在哪里可以找到完整的搜索路径?


  2. 添加搜索路径的所有可能方法是什么?


  3. 考虑到添加搜索路径(例如pathdef.m,startup.m,MATLABPATH env变量等)的所有可能的方法,添加搜索路径的顺序是什么?我认为这很重要,因为当不同搜索路径中存在同名的文件时,顶部的文件将被选中。



解决方案

Amro 提供的链接应该是很有帮助的回答你的问题。更具体地说:


  1. PATH 将显示 pathdef.m 文件的内容,其中应包括所有以下内容:




    • 提供MATLAB和其他MathWorks产品(即工具箱)的文件夹。这些文件夹位于根MATLAB文件夹中,您可以使用 MATLABROOT 函数。


    • Windows平台上的MATLAB用户文件夹(即 My Documents\MATLAB ),可以使用 USERPATH 功能找到。


    • 用户添加到路径文件的任何其他文件夹。




    完整的搜索路径包含上面的内容,加上当前的目录。当前目录不会保存为路径文件的一部分,因为它可以在MATLAB会话期间进行更改。您可以使用 PWD 功能查找当前文件夹。


  2. 搜索路径可以通过更改路径文件或当前目录来更改。您可以通过以下方式修改路径文件:





    可以通过以下方式更改当前目录:




  3. 使用上述方法修改路径文件时,通常将新文件夹添加到路径列表的顶部。您可以使用设置路径对话框



    当有共享相同的名称,MATLAB遵循以下函数优先级顺序,以确定要使用的函数:




    • 变量(如果变量与函数共享相同名称)


    • 嵌套功能


    • 子功能


    • 私人功能


    • 类构造函数


    • 重载方法


    • 当前目录中的功能


    • 功能在搜索路径上的其他位置




    请注意,当前目录中的函数在搜索路径上的其他位置之前被调用。此外,最靠近搜索路径顶部的文件优先于进一步向下的文件。



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.

这篇关于如何使用MATLAB搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆