gnuplot print column header with stats

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP


gnuplot print column header with stats



The gunplot stats command can be used to report stats for an input dataset. It creates a set of variables containing information about a specific column in the dataset. Here is an example of such use:


stats


set print "StatDat.dat"
do for [i=2:9] { # Here you will use i for the column.
stats 'data.dat' u i nooutput ;
print i, STATS_median, STATS_mean , STATS_stddev # ...
}
set print
plot "StatDat.dat" us 1:2 # or whatever column you want...



It would be useful to include the reported column header, something like:


print STATS_columnheader, STATS_median, STATS_mean , STATS_stddev # ...



However gnuplot does not provide the required STATS_columnheader variable.


STATS_columnheader



Is there an alternative way to achieve this ?




1 Answer
1



You can use an external tool such as awk to extract and return a column header. You can create a function like this:


awk


columnheading(f,c) = system("awk '/^#/ {next}; {print $".c.";exit}' ".f)



which, given a file f and a column number c, will return the column header. You'd use it like this:


f


c


print columnheading('StatDat.dat',i).' ', STATS_median, STATS_mean , STATS_stddev # ...



The awk expression skips all lines until the first non-comment line, prints the word given by the c parameter and exits. The printed word is returned by gnuplots system command.


c


system






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Arduino Mega cannot recieve any sketches, stk500_recv() programmer is not responding

Visual Studio Code: How to configure includePath for better IntelliSense results

Future solutions