1

I have a number of files with following order:

file_001.txt, file_002.txt, file_003_txt,
file_021.txt, file_023.txt, file_023.txt,
file_041.txt, file_042.txt, file_043.txt,
file_061.txt, file_062.txt, file_063.txt,
file_081.txt, file_082.txt, file_083.txt,
file_101.txt, file_102.txt, file_103.txt

I would like to plot each file in gnuplot using a loop. I can not able to make a loop. However my following script is working and looks a long script.

 plot,\
 for [i=1:3] 'file_00'$i'.txt' u 1:2,\
 for [i=1:3] 'file_02'$i'.txt' u 1:2,\
 for [i=1:3] 'file_04'$i'.txt' u 1:2,\
 for [i=1:3] 'file_06'$i'.txt' u 1:2,\
 and so on

How can I make the loop in any other efficient ways?

bibi
  • 3,671
  • 5
  • 34
  • 50
Kay
  • 1,957
  • 2
  • 24
  • 46
  • 1
    See http://stackoverflow.com/a/32359636/2604213, http://stackoverflow.com/q/29969393/2604213 or similar questions http://stackoverflow.com/search?q=%5Bgnuplot%5D+dir+ – Christoph May 10 '16 at 19:10

1 Answers1

1

You can use embedded loop:

plot for [j=0:10:2] for [i=1:3] 'file0'.j.i.'.dat' u 1:2;

#for [<var> = <start> : <end> {: <incr>}]
Tom Solid
  • 2,226
  • 1
  • 13
  • 32
  • How can I add another field to plot different distinct line. e.g. using 1:2, using 1:3, using 1:5, using 1:8. I mean `plot for [k=2, 3, 5, 8] for [j=0:10:2] for [i=1:3] 'file0'.j.i.'.dat' u 1:k;` – Kay May 11 '16 at 01:28
  • I see that you have got the answer at http://stackoverflow.com/questions/37151871/gnuplot-with-muliple-columns-using-loop :) But just to make this post full: use: `plot for [k in "2 3 5 8"]` `#for [ in "string of words"]` – Tom Solid May 11 '16 at 13:06