in reply to Re: Any idea for predicting the peak points in the graph by perl
in thread Any idea for predicting the peak points in the graph by perl

This node falls below the community's minimum standard of quality and will not be displayed.
  • Comment on Re^2: Any idea for predicting the peak points in the graph by perl

Replies are listed 'Best First'.
Re^3: Any idea for predicting the peak points in the graph by perl
by tlm (Prior) on Apr 18, 2005 at 11:58 UTC

    The following code assumes that the values are separated by white space (untested):

    use strict; my $input_file = 'foobar.txt'; open my $in, $input_file or die "Failed to read $input_file: $!\n"; my $max = do { local $_ = <$in>; chomp; [ split ] }; while ( <$in> ) { chomp; my ( $x, $y ) = split; $max = [ $x, $y ] if $y > $max->[ 1 ]; } close $in; print "max at ($max->[ 0 ], $max->[ 1 ])\n";

    Update: Minor change to original snippet (first data point is now read outside the while loop), plus additional snippet for the case of ordered smooth data.

    the lowliest monk

    A reply falls below the community's threshold of quality. You may see it by logging in.