Search code examples
gnuplot

Gnuplot reading file data of specific columns without plotting


I am new to Gnuplot and have some trouble. I want to read a file with 50 rows and 4 columns and print row 1+3 in a new document. With

set print "name.txt"
print "# X Y"
do for [i=1:50]{
    print i, error[i]   
}
set print

I can do the printing, but how can i read a file? (I don't want to plot anything)


Solution

  • Please check the manual and in the gnuplot console type help table. You can "plot" to a table. I already wrote the code when you were correcting your question. So, here you have 3 variations. So, you were apparently asking for the third one.

    Write column 1 and 3 into a new document:

    set table 'myOutputFile.dat'
        plot 'myInputFile.dat' u 1:3 with table
    unset table
    

    Write row 1 and 3 into a new document: (row counting starts with 0). Check help every.

    set datafile separator "\n"
    set table 'myOutputFile.dat'
        plot 'myInputFile.dat' u (strcol(1)) every 2::0::2 with table
    unset table
    set datafile separator whitespace  # set it back in case you have some more data
    

    Write the sum of column 1 and 3 into a new document:

    set table 'myOutputFile.dat'
        plot 'myInputFile.dat' u ($1+$3) with table
    unset table