in reply to Re^2: 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

You need to keep track of the sign of the y-delta of the last pair, and compare it to the sign of the y-delta of the current pair.

The following is a start. Input is not validated. Adjacent "peak" points with the same y value will be skipped -- you'll need to add some code for that. "Peak" points that occur on the first or last data point will be skipped. There may be an error on the first pair with some input.

Untested:

#!/your/perl/here use strict; use warnings; my $last_sign; my $last_y; my $last_x; while (<>) { my ($x,$y) = split; my $sign = $y <=> $last_y; if ( $last_sign <=> $sign ) { print "$last_x $last_y\n"; } $last_x = $x; $last_y = $y; $last_sign = $sign; }
Have the Homework Police cleared this yet?

-QM
--
Quantum Mechanics: The dreams stuff is made of

  • Comment on Re^3: Any idea for predicting the peak points in the graph by perl
  • Download Code