Page 1 of 1

search a big value on an array

Posted: Wed Nov 18, 2020 11:31 am
by Silvio.Falconi
If I have this array

aData:= { {"B", 0.2, 0.1 ,3.6 ,0.7},;
{"T", 0.2, 0.75 ,3.6 ,0.5},;
{"T", 0.2, 1.2 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.8 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4},;
{"T", 0.2, 1.6 ,3.6 ,0.4} }


I would like to find the largest number of the 4th array column ( adata[n][4])

how I must make ?
thanks

I made

nHeightold:= adata[1][4]

For n= 1 to Len(adata)
If adata[n][4]>nHeightold
nHeightBig:= adata[n][4]
nHeightold:= adata[n][4]
Endif


next

but I believe there is a better method

Re: search a big value on an array

Posted: Wed Nov 18, 2020 10:24 pm
by driessen
Silvio,

Why don't you sort the array first

aData := ASort(aData,,,{|x,y| (x[4]>y[4]})

The largest number is in adata[1,4].

Re: search a big value on an array

Posted: Fri Nov 20, 2020 8:24 pm
by FranciscoA
local nValMayor := 0, nCol := 4
AEval( aData, {|a| if( a[nCol] > nValMayor, (nValMayor := a[nCol], ) } )