运行 Octave 中其他脚本文件的脚本文件

Run script file from other script file in Octave

我有几个 运行 测试的 Octave 脚本文件,名为 test_1、test_2 等。我想要一个脚本文件 运行 所有测试,而不必将所有 test_n 文件切换为函数文件。我已经尝试了几种变体:

#!/path/to/octave -q
addpath('/path/to/directory/containing/all/scripts/');

source(test_1.m);

source(test_2.m);

但我总是得到 "error: invalid call to script /path/to/directory/containing/all/scripts/test_1.m"。

(我已经尝试了 source_file()、运行(),并且只在行中只包含文件名。)

有什么方法可以从 Octave 中的脚本文件 运行 脚本文件吗?

尝试

source test_1.m

source('test_1.m')

相反。

你的语法暗示 test_1 是一个结构变量,你正试图访问一个名为 m

的字段

run 命令相同(事实上,run 只是在幕后调用 source)。

您也可以直接调用脚本,如果它在路径上的话。您只需确保不包含 .m 扩展名,即

test_1
test_2

只需将包含的脚本的名称放在单独的一行中,不带 .m 扩展名。

让我们以脚本 1 为例:'enclosed.m' 和脚本 2:'included.m'。那么 enclosed.m 应该是这样的:

% begin enclosed.m
included;      % sources included.m
% end encluded.m