我正在安装一个 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 程序)中使用which
命令,那么它正在寻找 MATLAB 程序文件filename.m
或filename.p
,而不是常规的 Linux 二进制文件filename
。