How to use substrings in gnuplot -
i'd plot datafile using substrings column. data file contains data in format
1 (15, 3): dx: -1.619, dy: 3.315, dxsc: 0.981, dysc: 0.993 2 ( 4,16): dx: -0.540, dy: -0.540, dxsc: 0.992, dysc: 0.977 ... and i'd plot numbers between brackets (x,y) y against x, like:
plot "data.dat" u substr(($2),7,8 ):substr(($2),10,11) what correct syntax this?
doing gnuplot bit tricky, because gnuplot doesn't allow specifying arbitrary format input. usually, best way use external tool extract data , feed resulting file gnuplot (this done on-the-fly using syntax (plot '< script data.dat'...).
however, in case there hack working gnuplot following next steps:
- use
set datafile separator ':'have information of bothx,yin single column. use
strstrtdetermine start , end string positions ofx,yvalues.for
x-value besubstr(s, strstrt(s, "(")+1, strstrt(s, ",")-1)add
0.0resulting substrings have them implicitely converted real values.
a complete script, works example data is
set datafile separator ":" get_x(c) = 0.0 + substr(strcol(c), strstrt(strcol(c), "(") + 1, strstrt(strcol(c), ",") - 1) get_y(c) = 0.0 + substr(strcol(c), strstrt(strcol(c), ",") + 1, strstrt(strcol(c), ")") - 1) plot 'data.dat' using (get_x(1)):(get_y(1)) points pt 7 ps 2
Comments
Post a Comment