2

I have folders 10,11,12,...50. In all the folders I have data files "data.dat". I want to plot data from all these files in to a single ps file. Each file gets a page of their own. Like:

plot "10/data.dat" u 1:3 w l, "10/data.dat" u 1:4 w l, "10/data.dat" u 1:5 w l

plot "11/data.dat" u 1:3 w l, "11/data.dat" u 1:4 w l, "11/data.dat" u 1:5 w l

.....

plot "50/data.dat" u 1:3 w l, "50/data.dat" u 1:4 w l, "50/data.dat" u 1:5 w l

So each file gets their own page and the ps file will have 41 pages. How do I do that using some kind of loop structure in gnuplot? Or how should I use shell script?

1

1 Answer 1

2

You should use a do for since a plot for would plot all of them in a single page.

do for [i=10:41] {
    set title "Plot ".i
    plot "".i."/data.dat" u 1:3 w l, "" u 1:4 w l, "" u 1:5 w l
}
Sign up to request clarification or add additional context in comments.

4 Comments

Great! Thanks! One more question though. How do I set the title of the graph to the value of "i", ie, something like set title "plot for $i"
How should one use i in calculations? For example, set title "Plot" .i.-5 or set title "Plot" .i.*5
Never mind. I used set title sprintf("Plot %d",i-5). But it would be nice to know how to do the other way as well!
@PopulationXplosive . is the string concatenation operator which accepts a number or another string as the right operand so you could use it like "plot ".(i-5) or "plot ".(i*5). You should however note that numbers doesn't have this operator so i."/data.dat" would be an error but you could circumvent this by first applying to an empty string which is why i wrote "".i."/data.dat".

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.