gnuplot:从数据中的字符串中提取x值

时间:2021-07-02 14:58:35

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:

我想从第一列中的文件名的第4到第7个字符中提取x值。我尝试了以下用户功能:

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?

有没有办法在gnuplot中这样做而不先通过外部工具运行数据?

1 个解决方案

#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):

表达式$ 1是第(1)列的捷径,因此使用$ 1已经为您提供了相应列的数字表示。要获取字符串值,请使用stringcolumn(1)(不带$!)或strcol(1):

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

#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):

表达式$ 1是第(1)列的捷径,因此使用$ 1已经为您提供了相应列的数字表示。要获取字符串值,请使用stringcolumn(1)(不带$!)或strcol(1):

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