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?

1

1 Answer 1

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>}]
Sign up to request clarification or add additional context in comments.

2 Comments

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;
I see that you have got the answer at stackoverflow.com/questions/37151871/… :) But just to make this post full: use: plot for [k in "2 3 5 8"] #for [<var> in "string of words"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.