如何获取 GNU Octave 中的当前脚本路径?
How do I get the current script path in GNU Octave?
在 GNU Octave 中,如何获取脚本存储目录的路径?无论当前目录如何,我都希望它能正常工作。
这适用于 Octave 和 Matlab:
file_path = fileparts(mfilename('fullpath'));
函数 mfilename
returns the name of the script it is called from. When called with 'fullpath'
, it returns the full path to that file (including the file name and extension). fileparts
提取包含文件夹的路径。
请注意,如果从控制台调用,这将 return 一个空字符串。
如果你想知道另一个脚本在哪里,你也可以试试
以下命令:
which("myScript");
在 GNU Octave 中,如何获取脚本存储目录的路径?无论当前目录如何,我都希望它能正常工作。
这适用于 Octave 和 Matlab:
file_path = fileparts(mfilename('fullpath'));
函数 mfilename
returns the name of the script it is called from. When called with 'fullpath'
, it returns the full path to that file (including the file name and extension). fileparts
提取包含文件夹的路径。
请注意,如果从控制台调用,这将 return 一个空字符串。
如果你想知道另一个脚本在哪里,你也可以试试 以下命令:
which("myScript");