filterdata by name in gnuplot

Help
Mohamed
2013-07-15
2013-07-17
  • Mohamed

    Mohamed - 2013-07-15

    I have a data file that looks like this:

    a 1 2 3
    a 4 5 6
    b 6 7 9
    b 1 2 3

    and I want to plot only the lines where the first value is "a", is it possible with gnuplot?
    I need something like
    plot 'file.dat' using 2:($1==a ? $3 : 1/0) w lp

     
  • Christoph Bersch

    Use

    plot 'file.dat' using 2:(stringcolumn(1) eq "a" ? $3 : 1/0)

    Christoph

     
  • Mohamed

    Mohamed - 2013-07-15

    Awsome, it works think you

     
  • Mohamed

    Mohamed - 2013-07-15

    well, it worked for the first case, but when I try this

    plot 'mmm.dat' using (stringcolumn(1) eq "b" ? $3 : 1/0):(stringcolumn(1) eq "a" ? $3 : 1/0) w lp

    it doesn't work anymore

     
  • Christoph Bersch

    What does it mean "doesn't work"? Do you get an error message, a wrong plot?

    If I try the example you gave:

    file mmm.dat with content
    a 1 2 3
    a 4 5 6
    b 6 7 9
    b 1 2 3

    and

    plot 'mmm.dat' using (stringcolumn(1) eq "b" ? $3 : 1/0):(stringcolumn(1) eq "a" ? $3 : 1/0) w lp

    I get the message "warning: Skipping data file with no valid points", which is obvious, because with this data one of the two expressions always evaluates to 1/0, so all points are invalid.

    Christoph

     
  • Mohamed

    Mohamed - 2013-07-17

    Think you Christoph for your effort :)
    In fact, I get this error 'x range is invalid' and I undersatand that the coordinates of the points we want to plot must be in the same line. So, I managed to change the data file to solve my problem.

     

Log in to post a comment.