Search code examples
gnuplotoctavebinary-matrix

octave binary matrix for gnuplot


I need help in understanding how to use this octave script

http://www.gnuplotting.org/code/save_binary_matrix.m

to generate a binary matrix that I want to plot with gnuplot. Any suggestion will be appreciated even just a web link that would help me to understand octave syntax

thanks

Mariano


Solution

  • Octave syntax

    The octave syntax is not that hard to understand. The documentation of the interpreter can be found here.

    The main part of the script

    % Create matrix to store in the file
    1. MS = zeros(length(x)+1,length(y)+1);
    2. MS(1,1) = length(x);
    3. MS(1,2:end) = y;
    4. MS(2:end,1) = x;
    5. MS(2:end,2:end) = M';
    

    can be explained like this:

    1. Line 1 initializes a matrix MS of dimensions length(x) + 1 and length(y) + 1 where length determines the largest dimension of the argument. Since x and y are in your case vectors, length returns the dimension of the vector.

    2. After in Line 1 the matrix MS is created, the length of vector x is stored in MS(1,1). This is the first row element of the first column of MS.

    3. Line 3 assigns the rest of the first row (everything from the 2nd element to the end: hence 2:end the values of y.

    4. The rest of the first column gets all the values of x assigned to.

    5. The remaining matrix MS now gets all values of the transpose of M assigned.

    You basically end up with a matrix that has the y-axis stored in the first row and the x-axis stored in the first column. The remaining matrix MS holds the transpose of matrix M.

    Plotting a binary matrix with gnuplot

    As described here the format specified above is of the exact format as needed by gnuplot. You now have multiple ways of plotting matrix information. One simple way of testing your binary file is

    splot "Data.bin" binary w l
    

    where "Data.bin" has to be substituted for your binary file.

    A general introduction into plotting 3D information can be found here and there.