Page 1 of 1

Find Maximum in a Table

Posted: Thu Jun 30, 2011 3:36 pm
by jasmin
I have this program to find a maximum in column 1 with 5 rows, and finally highlight the maximum yellow:

Code: Select all

'find highest values for !i=1 to 5 !r=0 for !j=1 to 5 if table_a(!i,1)>=table_a(!j,1) then !r=!r+1 endif next if !r=5 then exitloop endif next table_a.setfillcolor(!i,1) yellow
Problem: It works well when all numbers are greater than 0. However, once a number is less then 0 (e.g. -0.23443) then it will fail to work. I wonder why does it fail to work? As far as I know 2>1 as well as 2>-1.

Re: Find Maximum in a Table

Posted: Thu Jun 30, 2011 3:40 pm
by EViews Gareth

Re: Find Maximum in a Table

Posted: Thu Jun 30, 2011 3:51 pm
by jasmin
Perfect! After I added the "@val" it works perfectly!!! Thanks agian.

Btw. I expted that you say that my program to find MAX is crap, but did not happen. :) Is the program more less how it's done? I quickly came out with this solution and it seems to work, but I always considered it a bit cumbersome.

Re: Find Maximum in a Table

Posted: Thu Jun 30, 2011 4:07 pm
by EViews Gareth
I didn't actually look at your program...

Seems something like this should work:

Code: Select all

!max = 1e-10 !r=0 for !i=1 to 5 !val = @val(table_a(!i,1)) if !val >= !max then !r = !i !max = val endif next