Hello I want to know how I can calculate the standard deviation of a column of a data file using gnuplot. I know gnuplot to refer to a column using n $ n, but how do I (could serve a function) to add all values of $ n. That's all I can't do in gnuplot and they do not want to have to use some external program. And since gnuplot uses the notation $ n, I guess that this is possible, but not how. Any suggestions?
3 Answers
there is a command for that: stats
example for using the whole 2nd column:
stats "filename" using 2 name "A"
this gives you detailed information in the terminal and you can use the data with the suffix (here "A") like:
plot "filename" t "data", A_mean t "mean value"
see also help stats
for more information on the command

- 2,117
- 13
- 26

- 91
- 1
- 2
-
Thanks! using it - is there a way to refer to a previously read dataset? I assume that the same file/column is read twice - once for stats another for plot – nhed Jul 14 '16 at 17:55
Play some tricks, gnuplot can do this kind of work. I have talked about "Statistic analysis using gnuplot" in two of my blog articles. The mean value, maximum, minimum, standard deviation are all covered. Here is the urls:
http://gnuplot-surprising.blogspot.com/2011/09/statistic-analysis-using-gnuplot-0.html
http://gnuplot-surprising.blogspot.com/2011/09/statistic-analysis-using-gnuplot-1.html
May be you can find what you want from these two articles!

- 1,049
- 8
- 6
-
2The linked material is very outdated now. The "stats" command does a much better job since the release of gnuplot 4.6.0 back in 2012. – Karl Jul 08 '15 at 13:35
AFAIK gnuplot cannot manipulate data of a complete column. There are various ways you can deal with row data, like adding them and so forth, but this does not apply to column data.
But there are two ways I can think of how you can get your standard deviation:
- You use an external program or export your data differently (that is if you have influence on the export algorithm
- You use an external program like awk inside gnuplot. Some samples of this approach are described here.

- 13,723
- 15
- 78
- 104