使用gnuplot访问数据文件中的第n个数据点 [英] accessing the nth datapoint in a datafile using gnuplot

查看:36
本文介绍了使用gnuplot访问数据文件中的第n个数据点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在gnuplot中搜索所有管道和内置函数之后,我仍然没有找到一种简单的方法来访问数据文件的第n个元素(而不是通过增量,单个值)以用作函数中的常量(或for循环中的参数).例如,我有一个两列的单调递减数据文件,我想在绘制时对y值进行归一化,因此y的范围是从一(1)到零(0),方法是从每个数据点减去最后一个值,然后用减法除以差值在第一个数据点和最后一个数据点之间.我尝试了awk,但是对语法不太熟悉.如果有一种简单的方法,我想知道.

After searching through all pipes to and inbuilt functions in gnuplot, I still haven't found a simple way to access the nth element of my datafile (not through increment, the single value) for use as a constant in a function (or parameter in a for loop) for my plots. For example I have a monotonic decreasing datafile with two columns and I want to normalize the y values while plotting so the y ranges from one (1) to zero (0) by subtracting the last value from each datapoint and dividing the subtraction by the difference between the first datapoint and the last. I tried awk but I'm not too familiar with the syntax. If there is a simple way I would love to know.

例如

使用1:((($ 2-'lastdatapoint')//''firstdatapoint'-'lastdatapoint'))绘制"my2columndata.dat"

plot "my2columndata.dat" using 1:(($2-'lastdatapoint')/('firstdatapoint'-'lastdatapoint'))

或第一个和最后一个数据点同义的某种东西-它们是单调递减数据文件"my2columndata.dat"中的第一个和最后一个数据点

or something of the sorts where first and last datapoints are eponymous - they are the first and last datapoints in the monotonic decreasing datafile "my2columndata.dat"

推荐答案

在您的情况下(因为您知道数据文件正在单调减少),这并不难做到.

In your case (since you know that the datafile is monotonically decreasing), this isn't too hard to do.

set terminal unknown
plot 'my2columndata.dat' # gather basic statistics
first=GPVAL_DATA_Y_MAX
last=GPVAL_DATA_Y_MIN

set terminal <whatever>
set output <whatever.wht>
plot 'my2columndata.dat' u 1:(($2-last)/(first-last))

此方法在不创建输出的情况下收集有关数据文件的信息,然后使用GPVAL变量重新绘制. (使用命令show variables all进行绘制后,您可以在gnuplot中看到它.)在gnuplot 4.6.0及更高版本中,您可以使用stats命令来收集数据而无需进行绘制,就像我在这里所做的一样. stats会创建不同的变量名称.

This method gathers information about the datafile without creating an output, then replots using the GPVAL variables. (You can see this in gnuplot after plotting with the command show variables all.) In gnuplot 4.6.0 and above you can use the stats command to gather data without plotting as I have done here; stats creates different variable names though.

访问第n个数据点(正如您的问题标题所暗示的那样)会比较棘手.

Accessing the n-th data point (as your question title hinted) would be trickier to do.

这篇关于使用gnuplot访问数据文件中的第n个数据点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆