Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Calculate the minimum and maximum data with 'Gnuplot'

4,321 views
Skip to first unread message

D.GH

unread,
May 20, 2008, 4:04:57 PM5/20/08
to
Hello,

I would like if is possible to calculate the maximum and minimum from
a data file.

My data in the following file (MyData.dat)

22.871536
22.029848
18.641526
11.097671
10.769791
14.375998
9.353067
16.888065
10.120260
11.920241
14.518588
26.042677
9.516011
16.486201
23.851848
10.483301

I do not know neither the maximum nor the maximum.
If I could calculate them with 'Gnuplot', it will help me with the
following code:
#############################
Min= .......
Max= .......
NumberBin=10
Shift=(Max-Min)/NumberBin
bin(x) = Min + Shift * int((x - Min) / Shift)
set style fill solid .2 border -8
plot 'MyData.dat' u (bin($1)):(1.0) title '' smooth frequency with
boxes
set term postscript eps color
set out 'Myfig.eps'
set size 0.7, 0.7
replot
#############################

Thank you for your ideas

Dariush

Oliver Jennrich

unread,
May 20, 2008, 5:07:54 PM5/20/08
to
"D.GH" <dariush.gh...@gmail.com> writes:

> Hello,
>
> I would like if is possible to calculate the maximum and minimum from
> a data file.

Yes. But the solution is far from ideal - gnuplot is a plotting tool,
not a data processing tool.

Anyway - you want to run once through the data and find the maximum
and the minimum:

------8<------8<------8<------8<------8<------8<-------
# Define two helper functions
ismin(x) = (x<min)?min=x:0
ismax(x) = (x>max)?max=x:0

# Initialise the 'global' vars
max=-1e38
min=1e38

# Run through the data and pass it to the helper functions.
# Any expression for the 'using' will do, as long as it contains both
# helper functions
plot "MyData.dat" u 0:(ismin($0)*ismax($0))

# Now, max and min will hold the maximum and minimum of column 0 of
# your data

print max
print min
------8<------8<------8<------8<------8<------8<-------

A different solution would require a working perl installation:

max=`! perl -e '$max=-1e38; while (<>) {@t=split; $max=$t[0] if $t[0]>$max}; print $max' < MyData.dat`


--
Space - The final frontier

nicola...@googlemail.com

unread,
May 21, 2008, 2:33:23 AM5/21/08
to
An other possibility imho would be to fit the data and calculate the
values from the derivative.

regards

Nicolas

goo...@catking.net

unread,
May 21, 2008, 1:41:37 PM5/21/08
to

> > Thank you for your ideas
>
> > Dariush

cleaning Oliver's answer , less work:

grab(x)=(x<min)?min=x:(x>max)?max=x:0;
plot 'datafile.dat' using 1:(grab($1))

you will need gnuplot 4.3 or cvs , this feature is relatively new.

D.GH

unread,
May 21, 2008, 3:12:48 PM5/21/08
to
On 20 mai, 23:07, Oliver Jennrich <oliver.jennr...@gmx.net> wrote:

Hello,

Thank you for your proposal, it does not work with me.
I have the following error message :

gnuplot> ismin(x) = (x<min)? min=x:0
^
"Test.gnu", line 2: expecting ':'

Thank you

Dariush

D.GH

unread,
May 21, 2008, 3:30:37 PM5/21/08
to

I have the following error message :

gnuplot> grab(x)=(x<min)?min=x:(x>max)?max=x:0;
^
"test4.gnu", line 1: expecting ':'

Dariush

goo...@catking.net

unread,
May 22, 2008, 9:15:24 AM5/22/08
to
On May 21, 9:30 pm, "D.GH" <dariush.ghorbanza...@gmail.com> wrote:

> > you will need gnuplot 4.3 or cvs , this feature is relatively new.
>
> I have the following error message :
>
> gnuplot> grab(x)=(x<min)?min=x:(x>max)?max=x:0;
>                             ^
>          "test4.gnu", line 1: expecting ':'
>
> Dariush

what gnuplot version are you using?

D.GH

unread,
May 22, 2008, 4:11:33 PM5/22/08
to

gnuplot version 4.2.3 -- binary distribution for MS-Windows 32bit

D.GH

unread,
May 25, 2008, 7:09:38 AM5/25/08
to
On 21 mai, 19:41, goog...@catking.net wrote:

Thank you

The code works with 'gnuplot 4.3.'

wenx...@gmail.com

unread,
Oct 12, 2018, 4:39:13 AM10/12/18
to
在 2008年5月20日星期二 UTC+2下午10:04:57,D.GH写道:

Chris Elvidge

unread,
Oct 12, 2018, 6:38:06 AM10/12/18
to
Use "stats" on datafile to get max and min values



--

Chris Elvidge, England
0 new messages