Find Maximum in a Table

For questions regarding programming in the EViews programming language.

Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt

jasmin
Posts: 19
Joined: Thu Jun 16, 2011 8:50 am

Find Maximum in a Table

Postby jasmin » Thu Jun 30, 2011 3:36 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Find Maximum in a Table

Postby EViews Gareth » Thu Jun 30, 2011 3:40 pm


jasmin
Posts: 19
Joined: Thu Jun 16, 2011 8:50 am

Re: Find Maximum in a Table

Postby jasmin » Thu Jun 30, 2011 3:51 pm

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.

EViews Gareth
Fe ddaethom, fe welon, fe amcangyfrifon
Posts: 13600
Joined: Tue Sep 16, 2008 5:38 pm

Re: Find Maximum in a Table

Postby EViews Gareth » Thu Jun 30, 2011 4:07 pm

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


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests