Last updated on June 16, 2020 by Dan Nanni
GNU Octave is an open-source alternative to MATLAB, a proprietary software and programming framework for conducting numerical mathematics and data analysis. If you are an Octave user, you are probably familiar with its interactive shell environment.
However, if you want to perform Octave-based analytics non-interactively in a batch processing environment, you need to be able to run Octave scripts from the command line.
Here is a simple Octave script example which you can use. The script accepts command line arguments.
$ vi hello.m
#!/usr/bin/octave -qf # example octave script arg_list = argv (); num = str2int(arg_list{1}); printf ("Name of Octave script: ", program_name ()); tic(); for i=1:num a(i) = i; endfor elapsed = toc(); printf("Elapsed time: %.4f seconds", elapsed);
Don't forget to make the script executable:
$ chmod 755 hello.m
At this point you can simply run the script as an executable.
$ ./hello.m 10000
This website is made possible by minimal ads and your gracious donation via PayPal or credit card
Please note that this article is published by Xmodulo.com under a Creative Commons Attribution-ShareAlike 3.0 Unported License. If you would like to use the whole or any part of this article, you need to cite this web page at Xmodulo.com as the original source.
Xmodulo © 2021 ‒ About ‒ Write for Us ‒ Feed ‒ Powered by DigitalOcean