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
> 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
regards
Nicolas
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.
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
I have the following error message :
gnuplot> grab(x)=(x<min)?min=x:(x>max)?max=x:0;
^
"test4.gnu", line 1: expecting ':'
Dariush
> > 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?
gnuplot version 4.2.3 -- binary distribution for MS-Windows 32bit