There has been discussion about this before. I don't think a solid case has been made that it gains enough to be worth the added complexity. The example you give wouldn't actually work anyway because autopromotion of a floating point value to a string is not well defined. And as soon as you bring a format into it, you might as well use the integer equivalent:
plot for [i=1:10] sprintf("mydata.%.1f", i/10.)
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The promotion to string can always be done by "".i
i.e. by concatenating with an empty string.
Your sprintf() solution is indeed a workaround, but it could actually make the script quite more complex and messy than it should be. Take for example an apparently simple case like:
pfor [i=8.562 : 12.137 : 0.065] "data_".i
This format would be clear and straight, and does not require one to work it around by something like:
which is clean enough. However, if it wasn't a big change, the direct iteration (without workarounds) would be best. There's really so much to change to get this?
Thank you,
Roberto
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
What you write is totally different from my case. You are just iterating among the 3 elements of an array, not among 55 elements of a sequence from 8.562 to 12.13 in steps of 0.065, as I would get from the system() call above.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
any feedback?
There has been discussion about this before. I don't think a solid case has been made that it gains enough to be worth the added complexity. The example you give wouldn't actually work anyway because autopromotion of a floating point value to a string is not well defined. And as soon as you bring a format into it, you might as well use the integer equivalent:
plot for [i=1:10] sprintf("mydata.%.1f", i/10.)
The promotion to string can always be done by "".i
i.e. by concatenating with an empty string.
Your sprintf() solution is indeed a workaround, but it could actually make the script quite more complex and messy than it should be. Take for example an apparently simple case like:
This format would be clear and straight, and does not require one to work it around by something like:
which is a quite unreadable way to get a simple iteration.
Last edit: cipper 2019-10-01
You are missing the point. What string is produced by
Without a format specifier the result of the automatic conversion is undefined.
You are right. I thought that the "".i trick worked also for floats...
rather, one could use the system() call (as you teach):
which is clean enough. However, if it wasn't a big change, the direct iteration (without workarounds) would be best. There's really so much to change to get this?
Thank you,
Roberto
No need to jump outside gnuplot and invoke the system shell.
There are multiple ways on doing this in gnuplot itself:
What you write is totally different from my case. You are just iterating among the 3 elements of an array, not among 55 elements of a sequence from 8.562 to 12.13 in steps of 0.065, as I would get from the system() call above.
Ah, sorry. I was not familiar with the "seq" command so I misinterpreted your example.