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

发布于 2024-12-12 17:29:55 字数 224 浏览 3 评论 0原文

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

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

另外,. 是我从 path 看到的第一个条目。这是否意味着我不需要添加任何目录,因为它总是首先搜索当前目录?

谢谢。

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.

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?

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

网白 2024-12-19 17:29:55

基本上,是的。

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

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

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

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 octaverc file is:

C:\Octave\3.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 cd to the data directory while still being able to use your functions.

你げ笑在眉眼 2024-12-19 17:29:55

您可以创建批处理文件,该文件将使用您的目录路径启动 Octave。请参阅下面的示例:

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

 -p means addpath()

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

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

 -p means addpath()
花想c 2024-12-19 17:29:55
addpath(pwd); savepath();

完毕。

addpath(pwd); savepath();

Done.

傲性难收 2024-12-19 17:29:55

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

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

  1. 启动 Octave。
  2. 创建新文件.m。
  3. 调用 newfile - 失败,因为 Octave 未注册其存在。
  4. addpath(pwd) - 导致 Octave 注册它。
  5. 关闭 Octave
  6. 启动 Octave - 现在 pwd 已从路径中消失,但 newfile.m 在启动时注册。
  7. 调用 newfile - 有效

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

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
心凉怎暖 2024-12-19 17:29:55

我在添加路径时遇到了类似的问题,其中直接在 Octave GUI(命令窗口)中使用 addpath 命令添加路径。添加的路径显示在控制台窗口中,但没有任何功能起作用。
通过将路径目录从Windows目录更改为未安装操作系统的其他方向解决了该问题。

I faced a similar problem in adding path where the path was added by using addpath command directly in Octave GUI (Command Window). The path added was being shown in console window but none of the functions worked.
The problem was solved by changing the path directory from Windows directory to some other direction where OS is not installed.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文