3
votes

I want to plot the data stored in bunch of files using gnuplot. If the files were named using sequential numbers, (eg. "1.dat" "2.dat", ...) I'd use something like

plot for [i=1:10] i.'.dat' u 1:2 w lp t 'I='.i;

However, the files are now named using powers of 2, i.e. "2.dat", "4.dat", "8.dat", .... I tried

plot for [i=1:10] (2**i).'.dat' u 1:2 w lp t 'I='.(2**i);

but I get the error

STRING operator applied to non-STRING type

I suppose this happens because gnuplot considers (2**i) as a floating point number rather than integer.

I'm sure there is a way to do what I want to do but as I'm very new to using the control statements of gnuplot I cannot find out how. Could someone please help me?

2

2 Answers

3
votes

You can use sprintf to convert a number to a string:

plot for [i=1:10] sprintf('%d',2**i).'.dat' u 1:2 w lp t 'I='.(2**i)

Interestingly, concatenating (2**i) with 'I=' in the title causes no problems.

3
votes

Try using an empty string ("") to commence the string concatenation operation. That is "".(2**i).".dat" instead of (2**i).".dat".