1

I've been trying to graph several files on the same gnuplot graph using sprintf to read in the filenames. I can read in one argument o.k. if I write:

filename(n) = sprintf("oi04_saxs_%05d_ave_div_sub.dat", n)
plot for [i=1:10] filename(i) u 1:2

then my graph is o.k and I get all files with that argument plotted on the same graph. However I have a string of characters that changes near the end of my filename and when I try to reflect this in

filename(n,m) = sprintf("oi04_saxs_%05d_0001_%04s_ave_div_sub.dat",n,m)

plot for [i=1:10] filename(i,m) u 1:2 

I get the following error message: 'undefined variable m'. I've tried removing the loop and just running

plot for filename(m)

and this results in the same error message. Help in understanding what's going wrong and how to fix it would be much appreciated :)

This is my full script:

unset multiplot
reset

set termoption enhanced
set encoding utf8

set term pdf size 18cm,18cm font 'Arial'

set pointsize 0.25

set output 'StoppedFlowResults.pdf'

set logscale

set xlabel '{/:Italic r} / [Q]'
set ylabel '{/:Italic Intensity}'

filename(n) = sprintf("./Result_curve-%d.txt/estimate.d", n)

myColorGradient(n) = sprintf("#%02x00%02x", 256-(n-1)*8-1, (n-1)*8)

set key off

set multiplot layout 2,1

filename(n,m) = sprintf("oi04_saxs_%05d_0001_%04s_ave_div_sub.dat",n,m);

plot for [i=1:10] filename(i,m) u 1:2 not

unset multiplot

set output
  • As the error message says: You don't define `m` anywhere before you use it with `plot for [i=1:10] filename(i,m)`. – Christoph Jan 07 '16 at 19:00
  • but don't I define it when I write filename(n,m)=sprintf("",n,m)? isn't that defining it from the list of potential filenames? – MoreTeaPlease Jan 11 '16 at 08:04
  • No, there you have a function definition, so the second function parameter is available as `m` inside the function body, but only there. It is a different issue when you call your `filename` function. And, now that I see it, you have two different `filename` definitions. – Christoph Jan 11 '16 at 08:47
  • Ok... this is helpful; but how do I solve the problem? I've just tried running the code by changing the second definition so it only reads in one variable so: `filename(n,m)=sprintf("", n,m) br/ plot for [i=1:10] filename(i) u 1:2 not` – MoreTeaPlease Jan 11 '16 at 13:12

1 Answers1

0

based on help for, you can have nested iterations e.g.:

plot for [i=1:3] for [j=1:3] sin(x*i)+cos(x*j)

In your case you can mix this with strings (you have yet to define string possible values) with something like:

plot for [i=1:3] for [m in "A B C D"] filename(i,m) u 1:2 not
bibi
  • 3,671
  • 5
  • 34
  • 50
  • so I have to define possible string values? I was hoping to use this as a workaround to that.... – MoreTeaPlease Jan 11 '16 at 08:06
  • Well, as @Christoph mentioned above, you have to tell gnuplot the pattern to find those files. Either you have a list of strings, either you glob in `ls` like stylle with a pattern as explained in [this post](http://stackoverflow.com/questions/26678584/plotting-curves-from-multiple-files-with-gnuplot) – bibi Jan 11 '16 at 23:37