Tuesday, July 5, 2011

Working with the columns of the data file

This post talks about how to control the information about the columns in a data file.

1) Once we want to plot the data contained in a data file, we can just write:
  • plot 'whatever.dat'
This will take the first column of the data file as the X coordinate and the second column as the Y coordinate.

2) In order to specify which column corresponds to each coordinate, we can write, for instance:
  • plot 'whatever.dat' u 3:2
It will take the data in the third column as the X coordinate and the data in the second column as the Y coordinate.

3) We can also treat any of the columns as a variable (previously defined):
  • COL=2
  • plot 'whatever.dat' u 3:COL

4) In order to perform mathematic operations to the number of any column, we must use parentheses:
  • COL=3
  • plot 'whatever.dat' u COL:(COL-1)

5) Nevertheless, if we want to operate the values contained in the column (not the number of the column), we have to use the dollar sign:
  • plot 'whatever.dat' u (cos($3)):5

6) Finally, if we want to perform the mathematic operation to the value of a column specified with a variable, we will have to use the function column:
  • COL=3
  • plot 'whatever.dat' u (cos(column(COL))):5

No comments:

Post a Comment