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?
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.
If you need spaces, insert them!
first = 1
lines = 350
set title sprintf("Secondary structure CA IX residues %d to %d", first, lines)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With