在 gnuplot 中循环 - 不同的文件夹
cycle in gnuplot - different folder
如何在gnuplot中使用这个命令?创建了一个图形,但随后将该图形作为数据文件读取并导致错误。
j=0;do for [i in system("ls")] { j=j+1; set term png; set output ''.i.'.png' ; p i w p lc rgb "navy" t ''.i }
我也试过:
j=0;do for [i in system (/media/)] { j=j+1; set term png; set output ''.i.'.png' ; p i w p lc rgb "navy" t ''.i }
但它是无效的表达式。如何为输出设置不同的文件夹?
或者如何把一个目录下的所有数据绘制成各种图形?是否可以在 gnuplot 中使用类似 *.r 的文件?
尽管根据使用的命令,您的问题在 Linux 下,但逻辑在 Windows 下是相同的。下面是一个例子。
假设有五个文件夹(folder01
到 folder05
),每个文件夹包含一个 .txt
文件(file01.txt
,...,file 05.txt
)。
以下脚本必须在父目录中,即包含其他文件夹的文件夹中。
set terminal pngcairo
# Under Windows, it saves the all .txt filenames.
# The search includes all subdirectories.
files = system("dir /b /s *.txt")
# Individual png files
do for [file in files]{
set output file[:strlen(file)-4] . '.png'
plot file u 1:2 w lp pt 6 pi -1 t file
}
# OR
# All files together
set key Left left reverse
set out "all_plots.png"
plot for [file in files] file u 1:2 w lp pt 6 pi -1 t file
个别地块的结果(缩略图):
所有地块的结果加在一起:
如何在gnuplot中使用这个命令?创建了一个图形,但随后将该图形作为数据文件读取并导致错误。
j=0;do for [i in system("ls")] { j=j+1; set term png; set output ''.i.'.png' ; p i w p lc rgb "navy" t ''.i }
我也试过:
j=0;do for [i in system (/media/)] { j=j+1; set term png; set output ''.i.'.png' ; p i w p lc rgb "navy" t ''.i }
但它是无效的表达式。如何为输出设置不同的文件夹?
或者如何把一个目录下的所有数据绘制成各种图形?是否可以在 gnuplot 中使用类似 *.r 的文件?
尽管根据使用的命令,您的问题在 Linux 下,但逻辑在 Windows 下是相同的。下面是一个例子。
假设有五个文件夹(folder01
到 folder05
),每个文件夹包含一个 .txt
文件(file01.txt
,...,file 05.txt
)。
以下脚本必须在父目录中,即包含其他文件夹的文件夹中。
set terminal pngcairo
# Under Windows, it saves the all .txt filenames.
# The search includes all subdirectories.
files = system("dir /b /s *.txt")
# Individual png files
do for [file in files]{
set output file[:strlen(file)-4] . '.png'
plot file u 1:2 w lp pt 6 pi -1 t file
}
# OR
# All files together
set key Left left reverse
set out "all_plots.png"
plot for [file in files] file u 1:2 w lp pt 6 pi -1 t file
个别地块的结果(缩略图):
所有地块的结果加在一起: