MATLAB / Octave Compatibility

I use Octave on my Linux-based workstations (Office, Home Laptops, Netbook, Server) and MATLAB on my Windows-based home desktop.

I’m currently writing up a (incomplete, to be sure) list of differences between MATLAB and Octave scripts — not so much as a comprehensive comparison but more as a stepping stone to automatic porting / validating that I want to do.

In the meantime, I figured I’d post my most frequently used compatibility functions. These functions add functionality to MATLAB that already exists in Octave. I don’t have many of these, and usually modify the code to be valid on both interpreters. There are a few exceptions, however, where I’ve become accustomed to specific syntax of Octave and would rather add the functionality to MATLAB than change my code.

Yes, these functions are simple. Yes, you could probably write most of these functions yourself. The idea is not to present solutions to difficult problems, but to provide you with a compatibility library that you can use to make porting scripts less painful.

As I get some more time, I’ll add some more of these, but here are my three most frequently used functions:


function len = printf( fmt, varargin )
    if nargin == 0
        len = fprintf(1, fmt);
        len = fprintf(1, fmt, varargin{:});


function r = rows(M)
    r = size(M,1);


function c=columns(M)
    c = size(M,2);
Posted Monday, February 21st, 2011 under octave / matlab.

Leave a Reply