我有一个由三列 x、y1 和 y2 组成的文件。我需要知道 y2 的最大值是多少。找到 y2 的最大值很容易:
stats 'test2-EDB.dat' u 3
从中我知道 y2 在文件的第 6779 行有最大值
STATS_index_max = 6779.0
但是,我需要的是文件第 6779 行的 x 值。你有什么建议吗?哪些最好是独立于平台的?
我在这里找到的解决方案(将数据集值读入gnuplot变量(X系列的开始))是:
at(file, row, col) = system( sprintf("awk -v row=%d -v col=%d 'NR == row {print $col}' %s", row, col, file) )
file="test2-EDB.dat" ; row=STATS_index_max ; col=1
c=at(file,row,col)
但是,我怀疑这个解决方案在 Windows 上是否也能正常工作(不知道,我没有使用它)。
致以最诚挚的问候, 莱昂纳多
您可以使用
every
作为 stats
命令来获取 x 值:
stats 'test2-EDB.dat' u 3
stats 'test2-EDB.dat' u 1 every ::STATS_index_max::STATS_index_max
print sprintf("x-value is %e", STATS_max)
我认为你可以做得更短更容易:
stats 'test2-EDB.dat' u 1:3 nooutput
print sprintf("Maximum at x=%g y=%g", STATS_pos_max_y, STATS_max_y)
应该与 gnuplot>=4.6.0(2012 年 3 月)一起使用