从 gnuplot 中的不同行获取特定元素的值

发布于 2024-07-08 04:09:56 字数 341 浏览 5 评论 0原文

使用 gnuplot 4.2,是否可以获取特定列/行的值并以某种方式使用该值?

例如,假设我的数据文件包含以下内容

#1  2
7  13
5  11
23 17
53 12

对于一个简单的绘图,其中第 1 列是 x 轴,第 2 列是 y 轴,我会: -

plot 'datafile' using 1:2

我想要做的是将第 2 列中的所有数据标准化为该列中的第一个元素 (13)。 有没有办法在 gnuplot 本身中做到这一点(即,不首先求助于脚本语言或其他东西来预处理数据)?

干杯

Using gnuplot 4.2, is it possible to obtain the value of a specific column/row and use that value somehow?

For example, let's say my datafile contains the following

#1  2
7  13
5  11
23 17
53 12

For a simple plot where column 1 is the x axis and column 2 is the y axis I would:-

plot 'datafile' using 1:2

What I'm trying to do is to normalize the all data in column 2 by the first element in that column (13). Is there a way to do this in gnuplot itself (i.e., without resorting to a scripting language or something to preprocess the data first)?

Cheers

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

风吹短裙飘 2024-07-15 04:09:56

使用运行平均值演示,我设法实现了标准化为第二列的第一个值的图。

base 变量用于存储引用值,first 函数在第一行初始化 base

first(x) = ($0 > 0 ? base : base = x)
plot file.dat u 1:(first($2), base/$2)

应该提到的是,这不是使用 gnuplot 4.2 完成的。

编辑:根据克里斯托夫的建议进行了更新。

Using the running averages demo, I managed to achieve a plot normalized to the first value of the second column.

The base variable is used to store the reference value, and the first function initializes base on the first row.

first(x) = ($0 > 0 ? base : base = x)
plot file.dat u 1:(first($2), base/$2)

It should be mentioned that this was not done using gnuplot 4.2.

Edit: Updated using Christoph's advice.

红尘作伴 2024-07-15 04:09:56

如果您的基值(例如 13)位于数据集的第一行,那么您应该能够使用 CVS 版本的 gnuplot 执行您想要的操作。

查看运行平均值演示。 按照这些思路,您可以编写一个自定义函数,在第一次调用时将基值存储在自定义变量中,并在后续调用时返回该变量。

(由于该演示仅针对 CVS 版本列出,因此我假设当前发行版本中不提供所需的功能。)

If your base value (e.g. 13) is in the first row of your data set, you should be able to do what you want using the CVS version of gnuplot.

Have a look at the running averages demo. Along those lines, you could write a custom function that stores the base value in a custom variable when called for the first time, and returns that variable on subsequent calls.

(Since that demo is listed for the CVS version only, I assume the required functionality is not available in the current release version.)

尝蛊 2024-07-15 04:09:56

您可以使用stats命令获取第二列的第一个值并将其存储在reference变量中,如下所示,

stats 'datafile' using (reference=$2) every ::0::0 nooutput

您可以替换$2 与您想要的任何其他列。 every ::0::0 中的零表示该列的第一个条目,您还可以使用 every ::n::n 获取该列的第 n 个条目柱子。 nooutput 用于避免控制台混乱。

然后您可以使用以下方法获得归一化图:

plot 'datafile' using 1:($2/reference)

You can use the stats command to get the first value of the second column and store it in the reference variable as shown below,

stats 'datafile' using (reference=$2) every ::0::0 nooutput

You can replace $2 with any other column you want. The zeros in every ::0::0 implies the first entry of the column and you can also use every ::n::n to get the nth entry of the column. nooutput is used to avoid the cluttered console.

You can then get normalized plot using,

plot 'datafile' using 1:($2/reference)
你穿错了嫁妆 2024-07-15 04:09:56

添加一个充满 13 的新列,然后使用:

plot 'datafile' using 1:($2/$3)

ad a new column full of 13, then use:

plot 'datafile' using 1:($2/$3)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文