Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.graphics.apps.gnuplot > #2634
| X-Received | by 10.182.81.37 with SMTP id w5mr9666684obx.29.1415371120123; Fri, 07 Nov 2014 06:38:40 -0800 (PST) |
|---|---|
| X-Received | by 10.50.30.132 with SMTP id s4mr46772igh.6.1415371120027; Fri, 07 Nov 2014 06:38:40 -0800 (PST) |
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!h15no7543297igd.0!news-out.google.com!ks2ni13482igb.0!nntp.google.com!h15no7543289igd.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail |
| Newsgroups | comp.graphics.apps.gnuplot |
| Date | Fri, 7 Nov 2014 06:38:39 -0800 (PST) |
| Complaints-To | groups-abuse@google.com |
| Injection-Info | glegroupsg2000goo.googlegroups.com; posting-host=122.249.243.114; posting-account=5JisHQoAAADMr3ysDKnlNc3lf_eH-hYV |
| NNTP-Posting-Host | 122.249.243.114 |
| User-Agent | G2/1.0 |
| MIME-Version | 1.0 |
| Message-ID | <63da4eac-2fda-4782-b6da-46b93921e95c@googlegroups.com> (permalink) |
| Subject | SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort |
| From | Kalin Kozhuharov <me.kalin@gmail.com> |
| Injection-Date | Fri, 07 Nov 2014 14:38:40 +0000 |
| Content-Type | text/plain; charset=ISO-8859-1 |
| Xref | csiph.com comp.graphics.apps.gnuplot:2634 |
Show key headers only | View raw
Hello, I have been thinking whether to post this or not for some time, but I decided to do it. It is generally a bad practice to abuse tools for what they are not meant to be, so use that only in a pinch. It is almost always a better idea to compute SMA in something like Perl before feeding your data to gnuplot, trust me. I just switched to such implementation myself ;-) But if you like hacking and inline messy code, here is a bash script that will generate gnuplot code for SMA with 2 to 53 bins (due to alphabet limitations; may be extended). https://github.com/thinrope/fixed_sensor_visualization/blob/master/SMA_gen.sh I will probably leave it there for quite some time (I am not using it anymore), but just in case the revision link: https://github.com/thinrope/fixed_sensor_visualization/blob/bbd373c355648220b419d71facd743a536e3a341/SMA_gen.sh It generates a code like that (for 3-bin and 6-bin): sma_3_init(x) = (b3=b2=b1=x); sma_3_shift(x) = (b3=b2,b2=b1,b1=x); sma_3_samples(x) = $0 > 2 ? 3 : ($0+1); sma_3_RO(x) = (b3+b2+b1)/sma_3_samples($0); sma_3(x) = (sma_3_shift(x), sma_3_RO(x)); sma_6_init(x) = (e6=e5=e4=e3=e2=e1=x); sma_6_shift(x) = (e6=e5,e5=e4,e4=e3,e3=e2,e2=e1,e1=x); sma_6_samples(x) = $0 > 5 ? 6 : ($0+1); sma_6_RO(x) = (e6+e5+e4+e3+e2+e1)/sma_6_samples($0); sma_6(x) = (sma_6_shift(x), sma_6_RO(x)); Then you can use it like: plot e=sma_6_init(0) "some_file" u 1:2 w p, "" u 1:(sma_6($2)) w l I wrote this script while debugging 24-bin SMA for the code used to generate some radiation sensor time-charts (http://gamma.tar.bz/nGeigies/) and it was working for some time, but I finally moved away from it. Hope I don't stir the pot too much, be happy and consider using the right tools for the job :-) Kalin.
Back to comp.graphics.apps.gnuplot | Previous | Next — Next in thread | Find similar | Unroll thread
SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort Kalin Kozhuharov <me.kalin@gmail.com> - 2014-11-07 06:38 -0800 Re: SMA (Simple Moving Average) inside gnuplot, ONLY AS LAST resort Hans-Bernhard Bröker <HBBroeker@t-online.de> - 2014-11-07 16:04 +0100
csiph-web