I have 1000 files named "data_i.dat", i->(1,1000). Each file is of the format
1 0.311 0.422 0.011
2 0.455 0.111 0.431
.
.
.
and so on. Now, I want to plot a graph with 1000 points where each point is the number in the 352nd row and 2nd column from each file. Is there a way to do this?
I tried writing
plot for[i=0:1000] sprintf('data_%d.dat',i) every ::352::352
which I know is not the correct direction, but I am not sure how to go about it.
The shortest way to plot the data would probably be:
plot for [i=1:1000] sprintf("data_%d.dat",i) every ::351::351 u (i):2 w lp pt 7
However, a plot for
-loop will plot the data from different files unconnected despite using with linespoints
.
Furthermore, keep in mind row index starts with zero. So, line 352 requires every ::351::351
.
So, my suggestion would be to collect the single datalines into a datablock first and then plot it connected with linespoints
. Check help with table
and help datablocks
.
Script:
### plot single lines from many different files
reset session
myFile(i) = sprintf("data_%d.dat",i)
set table $Data
plot for [i=1:1000] myFile(i) every ::351::351 u (i):2 w table
unset table
plot $Data u 1:2 w lp pt 7
### end of script