在gnuplot中查找数据文件的本地最大值 [英] Find local maximum of data files in gnuplot

查看:75
本文介绍了在gnuplot中查找数据文件的本地最大值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据列表(两列),我只想在gnuplot中绘制第二列具有局部最大值的值.

I have a list of data (two columns) and I want to plot in gnuplot only the value for which my second column has a local maximum.

这样做,我想看看第i行的第二列是否大于第(i-1)和第(i + 1)行.

To do so I would like to see if the second column of the ith row is bigger than the (i-1) and (i+1)th rows.

推荐答案

这是可以做到的,我对此感到无聊.我生成了以下随机数据集:

It can be done and I was bored enough to do it. I generated the following set of random data:

5191
29375
23222
32118
3185
32355
17173
8734
28850
20811
5956
6950
28560
25770
4630
28272
10035
7209
19428
26187
30784
20326
12865
23288
20924

根据值在列表中的位置绘制这些值看起来像这样:

Plotting the values against their position in the list looks like this:

您可以从上图立即发现局部最大值.现在,我可以处理将两个先前值(x和y坐标)存储在临时变量中的数据点,当我确定最大值时,可以绘制数据点:

You can spot the local maxima right away from the graph above. Now I can process the data points storing the two previous values (both x and y coordinates) in temporary variables, when I identify a maximum, I plot the data point:

# Select the columns of your data file that contain x and y data
# (usually 1 and 2 respectively)
xcolumn=0
ycolumn=1

plot "data" u (column(xcolumn)):(column(ycolumn)) w l, \
"data" u (column(0)==0 ? (last2y=column(ycolumn), \
last2x=column(xcolumn), 1/0) : column(0)==1 ? (lasty=column(ycolumn), \
lastx=column(xcolumn), 1/0) : lastx) \
: \
( column(0) < 2 ? 1/0 : (last2y < lasty && \
column(ycolumn) < lasty) ? (value=lasty, last2y=lasty, last2x=lastx, \
lasty=column(ycolumn), lastx=column(xcolumn), value) : (last2y=lasty, \
last2x=lastx, lasty=column(ycolumn), lastx=column(xcolumn), 1/0)) pt 7

这篇关于在gnuplot中查找数据文件的本地最大值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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