Retrieving non-zero minimum value of matrix column

For questions regarding programming in the EViews programming language.

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

diggetybo
Posts: 152
Joined: Mon Jun 23, 2014 12:04 am

Retrieving non-zero minimum value of matrix column

Postby diggetybo » Wed Feb 10, 2016 8:07 am

Hey there,

I'm having trouble retrieving the minimum of a matrix column, because it has to be non-zero. The @cmin command doesn't seem to work for this purpose, as to be expected, it retrieves the true min.

Is there anything that can I can bring to bear in this situation? I'd rather not resort to transforming the matrix to wipe the zeroes out, it would make everything else in my program really complicated.

[Edit] Even after transforming the zeroes to "NA", @cmin reads the minimum of the column as "NA". What to dooo....

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

Re: Retrieving non-zero minimum value of matrix column

Postby EViews Gareth » Wed Feb 10, 2016 9:24 am

Might be easiest just to write a loop and calculate the minimum manually.

diggetybo
Posts: 152
Joined: Mon Jun 23, 2014 12:04 am

Re: Retrieving non-zero minimum value of matrix column

Postby diggetybo » Wed Feb 10, 2016 9:37 am

yea, thanks for thinking it through with me. This is the best I could do:

(existing matrix called: m1)

Code: Select all

vector v1 = @columnextract(m1,1) for !i = 1 to @rows(v1) if v1(!i) = 0 then v1 = v1.@droprows(!i) exitloop endif next scalar v1_min = @cmin(v1)

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

Re: Retrieving non-zero minimum value of matrix column

Postby EViews Gareth » Wed Feb 10, 2016 9:55 am

That'd work. It might be marginally faster to calculate the minimum by hand.

Code: Select all

scalar min = m1(1,1) for !i=2 to @rows(v1) if m1(!i,1) < min and m1(!i,1) <> 0 then min = m1(!i,1) endif next

diggetybo
Posts: 152
Joined: Mon Jun 23, 2014 12:04 am

Re: Retrieving non-zero minimum value of matrix column

Postby diggetybo » Wed Feb 10, 2016 9:57 am

Oh that does cut down on things, good idea:) Last question! Let's say I save that as a variable

Code: Select all

!min = @cmin(v1)
Is there anyway I can search the original matrix "m1" and return the row+column number for !min?

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

Re: Retrieving non-zero minimum value of matrix column

Postby EViews Gareth » Wed Feb 10, 2016 10:30 am

Only manually.


Return to “Programming”

Who is online

Users browsing this forum: No registered users and 2 guests