开发者

plot if col A has substring

I need to do this in gnuplot:

plot 1:4 where col 2=="P1开发者_运维问答", col 3=="3", col 1 has substring "blur1"

Heres a dataset:

col_1          col_2        col_3    col_4
gcc.blur1.O0   P1           3        10.5
icc.blur1.O2   P2           5        9.8
gcc.blur2.O3   P2           3        8.9

Thanks in advance.


AFAIK you need to use an external script to check for substrings. Something like awk and use

plot "< awk '{...awk commands...}' input.dat"

If you just want to test col_2 for P1 you can do it in gnuplot via

f(x,y)= (x eq "P1"? y : 1/0)

plot "input.dat" u 3:(f(strcol(2),$4))

strcol(n) gets the n-ths column as a string. "eq" can be used to compare strings.


Such a simple check can be done with gnuplot's strstrt function. It returns the index of the first character found, or 0 if the substring wasn't found:

strstrt(strcol(3), 'blur1') > 0

So, your plot command can look like

matchesLine(col1, col2, col3) = strstrt(strcol(1), col1) > 0 && strcol(2) eq col2 && strcol(3) eq col3
plot 'file' using (matchesLine("blur1", "P1", "3") ? $1 : 1/0):4


If you know the exact position of the substring in advance, you can try to check for equality on that portion like this:

strcol(1)[5:9] eq 'blur1'

ps.: Here are some handy examples for dealing with strings in gnuplot:
http://gnuplot.sourceforge.net/demo/stringvar.html

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜