gnuplot: extract x-values from string in data

让人想犯罪 __ 提交于 2019-12-24 13:17:14

问题


My data files look like this:

c0e0100.dat 0.234
c0e0200.dat 0.857
...
c0e1200.dat 0.003

I would like to extract the x-values from the 4th to 7th character of the filenames in the first column. I tried the following user function:

str2num(s)=(s[4:7]+0.0)

and then:

plot 'file' using (str2num($1)):($2)

but this gives:

internal error: substring range operator applied to non-STRING type

I also tried:

plot 'file' using (str2num(stringcolumn($1))):($2)

but got the same result.

Is there a way of doing this in gnuplot without running the data through external tools first?


回答1:


The expression $1 is a short cut for column(1), so using $1 already gives you the numerical representation of the respective column. To get the string value, use stringcolumn(1) (without $!), or strcol(1):

str2num(s)=(s[4:7]+0.0)
plot 'file ' using (str2num(strcol(1))):2


来源:https://stackoverflow.com/questions/30130670/gnuplot-extract-x-values-from-string-in-data

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!