Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在gnuplot'中进行计算;s绘图命令_Gnuplot - Fatal编程技术网

在gnuplot'中进行计算;s绘图命令

在gnuplot'中进行计算;s绘图命令,gnuplot,Gnuplot,以下gnuplot代码运行良好: plot 'data.txt' using 2:4 ' %lf %lf %lf %lf' title "1 PE" with linespoints; 在下面的代码中,我想说:“使用第4列中的数字,然后将其除以第3列中的数字”。或者:“使用第2列中的数字,但除以常数2.0”。下面的代码演示了我试图实现的目标,但它不起作用 plot 'data.txt' using 2:4/4 ' %lf %lf %lf %lf' title "1 PE" wi

以下gnuplot代码运行良好:

plot 'data.txt'  using 2:4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;
在下面的代码中,我想说:“使用第4列中的数字,然后将其除以第3列中的数字”。或者:“使用第2列中的数字,但除以常数2.0”。下面的代码演示了我试图实现的目标,但它不起作用

plot 'data.txt'  using 2:4/4  '   %lf %lf %lf %lf' title "1 PE" with linespoints;
plot 'data.txt'  using 2:4/2.0  '   %lf %lf %lf %lf' title "1 PE" with linespoints;

这样做可能吗?

我通常不使用这种格式的数据文件,但我认为您需要的是:

#divide column 4 by column 3
plot 'data.txt'  using 2:($4/$3)  '   %lf %lf %lf %lf' title "1 PE" with linespoints

#divide column 4 by constant 10.0
plot 'data.txt'  using 2:($4/10.0)  '   %lf %lf %lf %lf' title "1 PE" with linespoints
作为补充说明,我认为没有任何理由将格式部分传递给此处使用。Gnuplot将数据文件拆分为空白:

plot 'data.txt'  using 2:($4/$3) title "1 PE" with linespoints

应该可以正常工作。

为了添加到给定的答案中,如果您更喜欢使用列名(当您的数据有标题时),则可以使用以下语法:

plot 'data.dat' using 'header1':(column('header2')*column('header3')) with lines
编辑
我的回答遭到了一些反对票,但我不知道为什么。虽然我可以很容易地找到如何使用数字列引用进行计算,但是在文档中或其他地方几乎找不到使用命名列的技巧,因此我仍然希望我的答案能够帮助其他人。

非常感谢,这很有效。还有,是的,格式字符串不是必需的,酷!把文件1中的一列除以文件2中的一列怎么样?@Ruzayqat——我已经有一段时间没有在Gnuplot中工作了,但在当时,没有办法这样做。您需要某种工具将列压缩在一起,然后您可以通过管道将数据导入。这实际上是一个非常有用的答案。