Port of Matlab code to Octave