by Sprint · 13y ago · 0 comments
$ octave
octave:1> a=load('numbers.txt');
octave:2> sum(a)
ans = 55
octave:3> mean(a)
ans = 5.5000
octave:4> std(a)
ans = 3.0277
octave:5> quantile(a)
ans =
1.0000
3.0000
5.5000
8.0000
10.0000
etcThe reason I wrote this script was to get quick results from the command line.
For instance: I could use grep, cut and other unix tools to get the numbers from a file and make quick calculations.
Of course, for complex processing I would use octave or R.
function mean() {
octave -q --eval "mean = mean(load('$1'))"
}
Then just run "mean numbers.txt".I am sure your approach is much quicker, octave takes a good 0.5s(!) to load on my machine.
Regarding speed, for simple calculations like sum, mean and variance, the bottleneck is in I/O.
octave -q --eval "mean = mean(load('$1'))"
But, again, octave requires more time to warm up...Basically you just need to write an octave function that reads values from the terminal.