0

My code is the following, I would like a to assume iteratives values like '3' , '4' and so on. My code is like:

a=2
#perform some basic operation like:
b=a*2
#convert it to string
c=str(b)
p path1 u 1:($1<=0?$@c:1/0) w filledcurves y=0 

The solution proposed on similar topic here so far did not work.

3 Answers 3

2

You should use this syntax

  c=''.b

c will be equal to 'b'

Sign up to request clarification or add additional context in comments.

Comments

1

gnuplot provides both sprintf (as in the C language routine) and a private implementation gprintf that offers formatting options beyond the normal ones provided by the C language. The full details with all supported format options are in the gnuplot documentation. A very simple use would be:

c = sprintf("%8.3f", b)

However, it makes no sense to convert the value to a string if your intent is to use it in a plot command that expects a number. There is no iteration in the pseudo-code you show so I can't guess exactly where you are headed with this but note that the operation @c to evaluate c as a macro expansion inside an iteration will always yield the content of c as it was prior to the iteration. So using the @ operator inside an iteration is almost always wrong.

Comments

0

If I correctly understand your minimal incomplete non-working example, I can only guess what you probably wanted to do, i.e. limit the plot of a dataset in a certain column which is selected by some variable. Correct? If my guess is true, I would do it the following way, no need for string conversion and the use of macros. Check help column.

a=2
# perform some basic operation like:
b=a*2
plot path1 u 1:($1<=0 ? column(b) : NaN) w filledcurves y=0 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.