我有几个运行测试的 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);
但我总是收到“错误:对脚本/path/to/directory/having/all/scripts/test_1.m 的无效调用”。
(我尝试过 source_file()、run(),并且只包含文件名。)
有没有办法从 Octave 中的脚本文件运行脚本文件?
最佳答案
尝试
source test_1.m
或
source('test_1.m')
相反。
您的语法暗示 test_1
是一个结构变量,并且您正在尝试访问名为 m
的字段
与run
命令相同(事实上,run
只是在底层调用source
)。
如果脚本位于路径上,您也可以直接调用该脚本。您只需确保不包含 .m
扩展名,即
test_1
test_2
关于matlab - 从 Octave 中的其他脚本文件运行脚本文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38647367/