如何同时遍历两个文件列表
How can I iterate through two file lists at the same time
我正在尝试从两个不同目录中的数据生成一堆(多)图,将它们称为 dirA 和 dirB。我正在使用多图,我希望每个图看起来像这样(请原谅我的艺术)...
其中绘图 A 是从 dirA 中的数据文件生成的,绘图 B 来自 dirB。
我已经试过了(简化了一点)...
filesA = system("ls dirA/*.dat")
filesB = system("ls dirB/*.dat")
i=0
do for [fn in filesA]{
set output 'anappropriatefilename.png'
set multiplot layout 1,2 rowsfirst
set size 0.25,1.0
plot fn using 1:2 with lines
set multiplot layout 1,2 rowsfirst
set size 0.75,1.0
plot filesB[i] 1:2 with lines
i=i+1
unset multiplot
}
但这给了我
':' expected
线上错误
plot filesB[i] 1:2 with lines
也许我只是不知道如何使用索引正确引用 filesB 数组?
或者也许有更好的方法来做到这一点?
我希望我能很好地解释我的问题,欢迎提出任何建议
谢谢
您有文件 A1,A2,...An
和 B1,B2,...Bm
。 m
总是等于 n
吗?输出文件应命名为 C1,C2,...Cn
?
以下示例在 windows 下工作。希望您可以将其调整为 Linux.
代码:
### create multiplots from different filelists (Windows)
reset session
unset multiplot
myDirA = 'dirA\'
myDirB = 'dirB\'
myType = '*.dat'
filesA = system('dir /b '.myDirA.myType) # Windows
filesB = system('dir /b '.myDirB.myType) # Windows
# spaces in path or filenames probably will create problems and would require a workaround
set terminal pngcairo size 800,200 font ",8"
# Assumption: number of filesA and number of filesB are identical
# and no spaces in path or filename
do for [i=1:words(filesA)] {
set output sprintf("myPlot%03d.png",i)
set multiplot layout 1,2
set origin 0,0
set size 0.25, 1.0
plot myDirA.word(filesA,i) u 1:2 w lines
set origin 0.25, 0
set size 0.75, 1.0
plot myDirB.word(filesB,i) u 1:2 w lines
unset multiplot
set output
}
### end of code
我正在尝试从两个不同目录中的数据生成一堆(多)图,将它们称为 dirA 和 dirB。我正在使用多图,我希望每个图看起来像这样(请原谅我的艺术)...
其中绘图 A 是从 dirA 中的数据文件生成的,绘图 B 来自 dirB。
我已经试过了(简化了一点)...
filesA = system("ls dirA/*.dat")
filesB = system("ls dirB/*.dat")
i=0
do for [fn in filesA]{
set output 'anappropriatefilename.png'
set multiplot layout 1,2 rowsfirst
set size 0.25,1.0
plot fn using 1:2 with lines
set multiplot layout 1,2 rowsfirst
set size 0.75,1.0
plot filesB[i] 1:2 with lines
i=i+1
unset multiplot
}
但这给了我
':' expected
线上错误
plot filesB[i] 1:2 with lines
也许我只是不知道如何使用索引正确引用 filesB 数组?
或者也许有更好的方法来做到这一点?
我希望我能很好地解释我的问题,欢迎提出任何建议
谢谢
您有文件 A1,A2,...An
和 B1,B2,...Bm
。 m
总是等于 n
吗?输出文件应命名为 C1,C2,...Cn
?
以下示例在 windows 下工作。希望您可以将其调整为 Linux.
代码:
### create multiplots from different filelists (Windows)
reset session
unset multiplot
myDirA = 'dirA\'
myDirB = 'dirB\'
myType = '*.dat'
filesA = system('dir /b '.myDirA.myType) # Windows
filesB = system('dir /b '.myDirB.myType) # Windows
# spaces in path or filenames probably will create problems and would require a workaround
set terminal pngcairo size 800,200 font ",8"
# Assumption: number of filesA and number of filesB are identical
# and no spaces in path or filename
do for [i=1:words(filesA)] {
set output sprintf("myPlot%03d.png",i)
set multiplot layout 1,2
set origin 0,0
set size 0.25, 1.0
plot myDirA.word(filesA,i) u 1:2 w lines
set origin 0.25, 0
set size 0.75, 1.0
plot myDirB.word(filesB,i) u 1:2 w lines
unset multiplot
set output
}
### end of code