Arrays gnuplot中的循环阵列
这一问题与该问题有关,并由该问题决定 gnuplot4.6引入了do命令。我如何使用它在例如文件和颜色的数组上循环?正确的语法是什么Arrays gnuplot中的循环阵列,arrays,loops,for-loop,gnuplot,Arrays,Loops,For Loop,Gnuplot,这一问题与该问题有关,并由该问题决定 gnuplot4.6引入了do命令。我如何使用它在例如文件和颜色的数组上循环?正确的语法是什么 colors = "red green #0000FF" files = "file1 file2 file3" do for [i=1:3] { plot files(i).".dat" lc colors(i) } 如果要将所有文件都放在一个绘图中,则需要使用“plot for[…”(自4.4版起支持)。使用“do for”(仅自4.6版起支持)循环多
colors = "red green #0000FF"
files = "file1 file2 file3"
do for [i=1:3] {
plot files(i).".dat" lc colors(i)
}
如果要将所有文件都放在一个绘图中,则需要使用“
plot for[…”
(自4.4版起支持)。使用“do for
”(仅自4.6版起支持)循环多个plot
命令,仅在multiplot
模式下工作
以下两种解决方案都在一个图中绘制所有数据,但在迭代中略有不同
第一种解决方案使用word
在打印时直接从字符串中提取单词
colors = "red green #0000FF"
files = "file1 file2 file3"
plot for [i=1:words(files)] word(files, i).'.dat' lc rgb word(colors, i)
第二种解决方案更改线型,然后直接在单词列表上迭代,而不是使用索引
colors = "red green #0000FF"
files = "file1 file2 file3"
set for [i=1:words(colors)] linetype i lc rgb word(colors, i)
plot for [file in files] file.'.dat'
我现在只是想测试一下。我更喜欢你的第二个解决方案,它不需要多点模式。它很有效。很好的解决方案。我不知道“单词”和“单词”尽管已经使用gnuplot十多年了。谢谢。@tommy.carstensen您使用do for..plot
的方法只能在multiplot
模式下工作。我的两种解决方案都使用plot for[…
并给出一个单独的绘图。我重新构建了答案来澄清这一点。感谢您的澄清。我还学会了“单词”和“单词”字符串变量演示中为那些希望更详细地研究它的人介绍了: