2

I have several Octave script files that run tests, named test_1, test_2, etc. I want to have a script file that will run all the tests, without having to switch all the test_n files to function files. I've tried several variations on this:

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

source(test_1.m);

source(test_2.m);

but I always get "error: invalid call to script /path/to/directory/containing/all/scripts/test_1.m".

(I've tried source_file(), run(), and just having the filename alone on the line.)

Is there any way to run script files from a script file in Octave?

2 Answers 2

4

Try

source test_1.m

or

source('test_1.m')

instead.

Your syntax implies test_1 is a struct variable and you're trying to access a field called m

Same with the run command (in fact, run simply calls source under the hood).

You can also call the script directly, if it's on the path. You just have to make sure you don't include the .m extension, i.e.

test_1
test_2
Sign up to request clarification or add additional context in comments.

3 Comments

To make sense of the error you're getting: Octave is telling you "ok, there's a file 'testo.m' in the path, which means there's a script / function called testo available for me to use. But I have no idea why you're telling me to access a member .m from it. That's no way to call a script or function! They don't even have members!"
By the way. If you intend your code to also be compatible with matlab, avoid the source approach, since this is octave-specific. run and calling a script directly (if on the path) are both fine.
0

Just put the name of the included script, without .m extension on a separate line.

Lets have for example script 1: 'enclosed.m' and script 2: 'included.m'. Then enclosed.m should look like:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.