bambino350
bambino350

Reputation: 304

gnuplot: extract x-values from string in data

My data files look like this:

c0e0100.dat 0.234
c0e0200.dat 0.857
...
c0e1200.dat 0.003

I would like to extract the x-values from the 4th to 7th character of the filenames in the first column. I tried the following user function:

str2num(s)=(s[4:7]+0.0)

and then:

plot 'file' using (str2num($1)):($2)

but this gives:

internal error: substring range operator applied to non-STRING type

I also tried:

plot 'file' using (str2num(stringcolumn($1))):($2)

but got the same result.

Is there a way of doing this in gnuplot without running the data through external tools first?

Upvotes: 1

Views: 1606

Answers (1)

Christoph
Christoph

Reputation: 48390

The expression $1 is a short cut for column(1), so using $1 already gives you the numerical representation of the respective column. To get the string value, use stringcolumn(1) (without $!), or strcol(1):

str2num(s)=(s[4:7]+0.0)
plot 'file ' using (str2num(strcol(1))):2

Upvotes: 1

Related Questions