Write m-files for Matlab and Octave

Some days ago, I needed to write an m-file (Matlab™ Function File), which had to run under Octave as well. If you use full Octave compliant stuff, this works quite easily without modification of your code. But if you use e.g. subplot(…) with a range to make one plot broader or wider, Octave resigns. Therefore, I put in the following statement and wrote this blog message as a reminder :)

if exist('OCTAVE_VERSION')
  figure
else
  subplot( 4,1,[2:4] )
end

This runs under both, Matlab™ and Octave. Hope, this helped…

Cheers, iss