gnuplot中的循环结构? [英] Loop structure inside gnuplot?

查看:59
本文介绍了gnuplot中的循环结构?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以迭代地从多个文件中检索数据并将它们绘制在gnuplot的同一图形上.假设我有data1.txt,data2.txt ...... data1000.txt之类的文件;每个具有相同的列数.现在我可以写一些类似的东西-

Is there any way to iteratively retrieve data from multiple files and plot them on the same graph in gnuplot. Suppose I have files like data1.txt, data2.txt......data1000.txt; each having the same number of columns. Now I could write something like-

plot "data1.txt" using 1:2 title "Flow 1", \
     "data2.txt" using 1:2 title "Flow 2", \
      .
      .
      .
     "data1000.txt"  using 1:2 title "Flow 6"

但这真的很不方便.我想知道是否有一种方法可以遍历gnuplot中的 plot 部分.

But this would be really inconvenient. I was wondering whether there is a way to loop through the plot part in gnuplot.

推荐答案

肯定存在(在gnuplot 4.4及更高版本中):

There sure is (in gnuplot 4.4+):

plot for [i=1:1000] 'data'.i.'.txt' using 1:2 title 'Flow '.i

变量i可以解释为变量或字符串,因此您可以执行类似的操作

The variable i can be interpreted as a variable or a string, so you could do something like

plot for [i=1:1000] 'data'.i.'.txt' using 1:($2+i) title 'Flow '.i

如果您想使线彼此偏移.

if you want to have lines offset from each other.

在gnuplot命令行中输入help iteration以获得更多信息.

Type help iteration at the gnuplot command line for more info.

也请务必查看@DarioP关于do for语法的答案;可以使您更接近传统的for循环.

Also be sure to see @DarioP's answer about the do for syntax; that gives you something closer to a traditional for loop.

这篇关于gnuplot中的循环结构?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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