你如何在 Octave 中获得你的路径(在 Windows 上)?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7936457/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 08:52:25  来源:igfitidea点击:

How do you get your path in Octave (on Windows)?

windowspathoctave

提问by B Seven

I used addpath(pwd)to get my .m files working in my projects directory. When I close the window and start a new window, the path I just added is gone. But the files still run.

我曾经addpath(pwd)让我的 .m 文件在我的项目目录中工作。当我关闭窗口并启动一个新窗口时,我刚刚添加的路径消失了。但文件仍在运行。

Is it in my path or not? How do I see the directories I have added to my path?

它是否在我的道路上?如何查看已添加到路径中的目录?

Also, .is the first entry I see from path. Does that mean I don't need to add any directories because it will always search the current directory first?

此外,.是我从path. 这是否意味着我不需要添加任何目录,因为它总是首先搜索当前目录?

Thanks.

谢谢。

回答by voithos

Basically, yes.

基本上,是的。

You can add a directory to the search path using addpath(), but as you know, it only exists for the current session and is reset when you restart Octave. If you want a path to survive between sessions, add it to your octaverc, a script file that gets run whenever a new session gets started. Example path to octavercfile is:

您可以使用 将目录添加到搜索路径中addpath(),但如您所知,它仅存在于当前会话中,并在您重新启动 Octave 时重置。如果您希望在会话之间保留一条路径,请将其添加到您octaverc的脚本文件中,该脚本文件会在新会话开始时运行。octaverc文件路径示例为:

C:\Octave.2.4_gcc-4.4.0\share\octave\site\m\startup

Since .is in your path by default, Octave will search your current directory for any function files that it needs. Using addpath(pwd)is somewhat useless if you're just going to stay in the same directory. However, there are some cases where it'd be useful, if for example you have a directory that contains your functions, and another one that has the data that you're working on: you could start in the functions directory, do addpath(pwd), and then cdto the data directory while still being able to use your functions.

由于.默认情况下在您的路径中,Octave 将在您当前目录中搜索它需要的任何函数文件。addpath(pwd)如果您只是要留在同一目录中,则使用有点无用。但是,在某些情况下它会很有用,例如,如果您有一个包含函数的目录,另一个包含您正在处理的数据的目录:您可以从函数目录开始, doaddpath(pwd)和然后cd到数据目录,同时仍然可以使用您的功能。

回答by user2630676

You can create batch file, which will start Octave with your directory path. Please see example below:

您可以创建批处理文件,它将以您的目录路径启动 Octave。请看下面的例子:

octave-3.6.4.exe -p "C:\MyOctaveDiretory"

 -p means addpath()

回答by Dan Danciu

addpath(pwd); savepath();

Done.

完毕。

回答by Petter Sourcecurrent

I think there is a bug in Octave (I use version 4.0.3 on Windows). When I create a new file in current path, this can't be called by Octave ("error: 'foo' undefined near line 1 column 1"). If I restart Octave, it works. This addpath(pwd) trick helps me a lot (before I unsuccessfully tried rehash() and cd elsewhere and back again).

我认为 Octave 中存在一个错误(我在 Windows 上使用 4.0.3 版)。当我在当前路径中创建一个新文件时,Octave 无法调用它(“error: 'foo' undefined near line 1 column 1”)。如果我重新启动 Octave,它会起作用。这个 addpath(pwd) 技巧对我有很大帮助(在我在其他地方尝试 rehash() 和 cd 并再次尝试失败之前)。

If you had the same problem, the reason for the symptom might be:

如果您遇到同样的问题,出现该症状的原因可能是:

  1. Start Octave.
  2. Create newfile.m.
  3. Call newfile - fails since Octave did not register its existence.
  4. addpath(pwd) - causes Octave to register it.
  5. Close Octave
  6. Start Octave - now pwd is gone from path, but newfile.m is registered at startup.
  7. call newfile - works
  1. 开始八度。
  2. 创建新文件.m。
  3. 调用 newfile - 失败,因为 Octave 没有注册它的存在。
  4. addpath(pwd) - 导致 Octave 注册它。
  5. 关闭八度
  6. 启动 Octave - 现在 pwd 已从路径中消失,但 newfile.m 在启动时已注册。
  7. 调用 newfile - 有效