如何从列中的所有其他值中的第一行中减去值?

发布于 2025-02-09 07:40:57 字数 302 浏览 1 评论 0原文

我想从文件的第一行减去文件的所有行,然后绘制它。如何在GNUPLOT中实施此类数学工作? 这是我想做的示例:

”在此处输入图像说明“

假设我有一个文件,该文件具有两个列和1000行。我想要一个从第一行中的第二列值中减去第二列中所有数据的脚本。

I want to subtract all rows of a file from its first row, and then plot it. How can I implement such math work in gnuplot?
Here is an example of what i want to do:

enter image description here

Let's say i have a file that has two columns and 1000 rows. I want a script that subtract all data's in 2nd column from the 2nd column value in first row.

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

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

发布评论

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

评论(1

明明#如月 2025-02-16 07:40:57

我很确定关于类似的问题,因此,显然并不容易找到。
我会搜索“归一化”或“偏移”。

即使您的数据中有单个或双空行,也可以使用以下示例。图命令中的表达式使用序列评估,检查帮助操作员二进制

有时,您可能会使用伪综合0(检查help pseudoColumns)看到类似的解决方案,但是,如果数据中有空行,这可能会导致错误的结果。

脚本:

### offset data: subtraction of first value in a column
reset session

$Data <<EOD
 0   10
 1   11
 2   12
 3   13
 4   14
 5   15
 6   16
 7   17
EOD

plot t=0 $Data u 1:(t==0?y0=$2:0,t=t+1,$2-y0) w lp pt 7 lc "red"
### end of script

结果:

”在此处输入图像描述”

I am pretty sure that there are a similar questions on SO, however, apparently not so easy to find.
I would have searched for "normalization" or "offset".

The following example works even if you have single or double empty lines in your data. The expression in the plot command uses serial evaluation, check help operators binary.

Sometimes, you might see similar solutions using the pseudocolumn 0 (check help pseudocolumns), however, which might lead to wrong results if you have empty lines in your data.

Script:

### offset data: subtraction of first value in a column
reset session

$Data <<EOD
 0   10
 1   11
 2   12
 3   13
 4   14
 5   15
 6   16
 7   17
EOD

plot t=0 $Data u 1:(t==0?y0=$2:0,t=t+1,$2-y0) w lp pt 7 lc "red"
### end of script

Result:

enter image description here

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