'which'命令在 MATLAB 中不起作用



我正在安装一个 MATLAB 工具箱,它通过调用来查找文件

which

当我打字时

which filename 

在抨击中,我得到了

/usr/local/bin/filename. 

which('filename')

在 MATLAB 命令窗口中说

'filename' not found. 

我可以看到二进制文件在

/usr/local/bin.

/usr/local/bin

被添加到 MATLAB 搜索路径中,所以我不确定这里发生了什么。有什么建议吗??

谢谢!!艾莎

你可以

在这里使用存在而不是哪个。如果文件存在,则 exists 将返回代码 2。

但是,这确实有效。例如,我的搜索路径中的.pdf文件:

>> which('Fritsch FN - Monontone piecewise cubic interpolation')
'Fritsch FN - Monontone piecewise cubic interpolation' not found.

看到找不到它的内容,但是当我提供全名(包括扩展名)时,可以正常工作。

>> which('Fritsch FN - Monontone piecewise cubic interpolation.pdf')
/Users/woodchips/Desktop/Fritsch FN - Monontone piecewise cubic interpolation.pdf

当然,存在也是有效的。

>> exist('Fritsch FN - Monontone piecewise cubic interpolation.pdf','file')
ans =
     2

我的猜测是,您的问题出现是因为您未能包含扩展名。它显然根据文档自动查找 .m、.p 和 .mdl 文件。

bash which 只在 Linux 路径中查找可执行文件。MATLAB which命令只定位 MATLAB 文件(*.m*.p 和 MDL 文件,根据 MATLAB which命令的文档)。MATLAB which 不会找到其他二进制文件。在大多数情况下,可以使用 bash which 和 MATLAB which来定位文件,如果该文件以 *.m*.p 命名,并且其目录同时位于 Linux 路径和 MATLAB 路径中。

我假设你在/usr/local/bin/filename,但不是filename.m.问题也可能是filename.m的路径不在 MATLAB 路径中。使用path命令检查和修改 MATLAB 路径,或使用菜单:文件 -> 设置路径。

因此,如果在某些 MATLAB 工具箱的安装

脚本或安装函数(MATLAB 程序)中使用which命令,那么它正在寻找 MATLAB 程序文件filename.mfilename.p,而不是常规的 Linux 二进制文件filename

最新更新