Reputation: 228
I am trying to add text+variable+text+variable into the title of the plot in gnuplot batch file.
I have variables lines and last containing numbers(1 and 350) and the code Ive got is:
set title sprintf("Secondary structure CA IX residues".first,"to".lines)
It prints: "Secondary structure CA IX1".
Can anyone help how to write this correctly, so that it will write Secondary structure CA IX residues 1 to 350 with gaps?
Upvotes: 2
Views: 7659
Reputation: 74615
You have two options:
Use the .
operator to concatenate your variables into strings:
set title "Secondary structure CA IX residues " . first . " to " . lines
I have added in spaces between the "
and .
for clarity, these will not be featured in the output. You are responsible for adding in the appropriate spaces in the string sections.
Use sprintf
as it was intended:
set title sprintf("Secondary structure CA IX residues %d to %d", first, lines)
The first argument to sprintf
is a format string, which should not contain any variables. Placeholders (such as %d
) are used to indicate the positions that variables should be inserted. Subsequent arguments to the function are the variables to be inserted. As your two variables appear to be integers, %d
is the appropriate format specifier to use.
Upvotes: 9
Reputation: 48390
If you need spaces, insert them!
first = 1
lines = 350
set title sprintf("Secondary structure CA IX residues %d to %d", first, lines)
Upvotes: 1