[proFit-list] Finding the min or max of data
Davide Guarisco
guarisco at sbcglobal.net
Thu May 9 22:15:16 CDT 2013
Then you have never dealt with large amount of data. I do, and I can assure you that pro Fit takes an awfully long time to sort a substantial data file (when it doesn't hang).
But I happen to have a fondness for good and efficient programming, and sorting really isn't the way to solve this problem. The best sorting algorithms behave as O(n log n), whereas this problem can be solved in O(n).
Consider this simple code:
procedure findminmax(var xmin,xmax: extended;var imin,imax: integer);
{Finds the minimum (xmin), maximum (xmax) values and their indices of the Y column of the current data window}
var ymin,ymax,yx: extended;
i: integer;
begin
ymin:=InvalidNum;
ymax:=InvalidNum;
imin:=InvalidNum;
imax:=InvalidNum;
{Find first valid data}
for i:=1 to NrRows do
if not(invalid(data[i,YColumn])) then
begin
ymin:=data[i,YColumn];
ymax:=ymin;
imin:=i;
imax:=imin;
Leave;
end;
for i:=i+1 to NrRows do
begin
if not(invalid(data[i,YColumn])) then
begin
yx:=data[i,YColumn];
if yx>ymax then
begin
ymax:=yx;
imax:=i
end
else
if yx<ymin then
begin
ymin:=yx;
imin:=i
end;
end;
end;
xmin:=ymin;
xmax:=ymax
end; {findminmax}
I think this does what the OP asked for.
Davide
On May 9, 2013, at 8:19 AM, Camaioni, Donald M wrote:
> Hi Davide,
>
> It can be programmed via a single command using pro Fit's built in sort routine, e.g., in pro Fit's Pascal programming language:
>
> Sort(window , referenceCol , order , selectionOnly );
>
> Efficiency of this routine has never been an issue for me.
>
> Don
>
> On May 9, 2013, at 7:44 AM, Davide Guarisco wrote:
>
> I would advise against doing that. Sorting is extremely inefficient.
>
> Davide
>
>
>
>
>
> On May 8, 2013, at 7:15 AM, Camaioni, Donald M wrote:
>
> I am thinking you would just sort the data and read values from either the resulting first or last row. -Don
>
> On May 8, 2013, at 6:54 AM, Dave wrote:
>
> Hi folks,
>
> While I am anxiously awaiting the Cocoa based, Retina- ready version of pro Fit, a question:
>
> Is there an easy way to find the local minima/ maxima of a set of data or selection of data, and report that point? I mean finding the max or min y value and reporting the x,y coördinate.
>
> Thanks,
> Dave
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com<mailto:proFit-list at quantum-soft.com>
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
>
>
>
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com<mailto:proFit-list at quantum-soft.com>
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
>
>
>
> _______________________________________________
> proFit-list mailing list
> proFit-list at quantum-soft.com<mailto:proFit-list at quantum-soft.com>
> http://quantum-soft.com/mailman/listinfo/profit-list_quantum-soft.com
>
>
> ––––––––––––––––––––––––––––––––
> Donald Camaioni, PhD
> Staff Scientist
> Catalysis Science Group
> PHYSICAL SCIENCES DIVISION
>
> Pacific Northwest National Laboratory
> 902 Battelle Boulevard
> P.O. Box 999, MSIN K2-57
> Richland, WA 99352 USA
>
> Tel: (509) 375-2739
> donald.camaioni at pnnl.gov<mailto:donald.camaioni at pnnl.gov>
> www.pnl.gov<http://www.pnl.gov/>
>
>
Davide
--
Davide Guarisco
5143 Halifax Dr.
San José, CA 95130
Home: (408) 376-0898
More information about the proFit-list
mailing list