• The most straightforward way is to install the MATLAB interface to Madagascar. When installing Madagascar, run
    ./configure API=matlab

    The configure script will try to find and test matlab and mex executibles on your system. If they are not in your PATH, you can specify them with

    ./configure API=matlab MATLAB=/path/to/matlab MEX=/path/to/mex

    Install Madagascar as usual, set MATLAB path to $RSFROOT/lib, and you will able to read and write RSF files from MATLAB using rsf_read, rsf_write, and other functions from the Madagascar interface.

  • Alternatively, you can try reading binary data using MATLAB functions, as in the following example

    % get in=, n1=, and n2= parameters from file.rsf
    [stat,in] = unix(‘sfget in parform=n < file.rsf’)
    in = strtrim(in)
    [stat,n1] = unix(‘sfget n1 parform=n < file.rsf’)
    n1 = str2num(n1)
    [stat,n2] = unix(‘sfget n2 parform=n < file.rsf’)
    n2 = str2num(n2)
    % read binary data
    fid = fopen(in,‘rb’)
    data = fread(fid,n1*n2,‘float32’);
    % reshape to 2-D matrix
    data = reshape(data,n1,n2);
  • An even better alternative is to abandone MATLAB in favor of free software, such as GNU Octave, Python with NumPy, Sage, etc. A Python interface to Madagascar is installed by default.