gnuplot:从数据中的字符串中提取x值 [英] gnuplot: extract x-values from string in data
本文介绍了gnuplot:从数据中的字符串中提取x值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的数据文件如下:
c0e0100.dat 0.234
c0e0200.dat 0.857
...
c0e1200.dat 0.003
我想从第一列中文件名的第4到第7个字符中提取x值. 我尝试了以下用户功能:
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)
然后:
plot 'file' using (str2num($1)):($2)
但这给出了:
internal error: substring range operator applied to non-STRING type
我也尝试过:
plot 'file' using (str2num(stringcolumn($1))):($2)
但是得到了相同的结果.
but got the same result.
是否有一种方法可以在gnuplot中执行此操作,而无需先通过外部工具运行数据?
Is there a way of doing this in gnuplot without running the data through external tools first?
推荐答案
表达式$1
是column(1)
的捷径,因此使用$1
已经为您提供了相应列的数字表示形式.要获取字符串值,请使用stringcolumn(1)
(不带$
!)或strcol(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
这篇关于gnuplot:从数据中的字符串中提取x值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文