0

I just discover gnuplot 4.6 and the beautiful loop tool. I want to plot a curve with different x axis, but it doesnt work. I have a file called file.txt, where there is a list of data like :

E002 = ...

E003 = ...

.

.

.

E021 = ...

The point is to shift the x axis of each plot with the corresponding data, something like this :

load 'file.txt'
plot for [a=2:21] 'my_data_file.dat' u ($1+'E00'.a ):a w l

But this doesn't work, and I have the error : 'Non-numeric string found where a numeric expression was expected'.

I do not know how to bypass this issue.

Second question, i would like after to sum all the column but shifted like before. Something like :

($1+E002):$2 + ($1+E003):$3 +...

Is there a way to do that ?

1 Answer 1

2

For the first question, you need to use the value to get the value of a variable.

I suggest to use a more versatile sprintf command to manipulate strings:

plot for [a=2:21] 'my_data_file.dat' u ($1+value(sprintf('E%03d',a))):a w l

Type help value and help sprintf to get more info about those commands

I don't understand very well the second question, maybe something like this could help?

my_sum=0
plot for [a=2:21] my_val=value(sprintf('E%03d',a)), my_sum=my_sum+my_val, 'my_data_file.dat' u ($1+my_val):a w l

print my_sum

the last line, should print the sum of all you Exxx values.

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

4 Comments

THANKS, the first solution is working !!! Regarding the second question, i want to sum the value in each column ($2+$3+...) and plot it but i want that the value (if we consider $2 like a fonction): $2 ($1+E002) +$3($1+E003). DO you know what i mean ?
sorry it's still unclear... particularly the part (if we consider $2 like a fonction): $2 is the second column of your data... in your question you say ($1+E002):$2 + ($1+E003):$3 +... this is the sum of two plots? try to write a script for just 2-3 columns and we'll se if with loops we can extend to any column size
Okay, if i have a function f and an other function g, i can plot easily f(x+E002) + g(x+E003) along x. So if i have many different functions, i can sum them with a loop or not and plot the sum. I wat to do the same but not with function, with my columns. I want to plot the sum of each column but shifted like for the function. I do not know if it is possible with column, even with only two.
Still unclear, but does this imply that you need to interpolate the values?

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.