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....
Retrieving non-zero minimum value of matrix column
Moderators: EViews Gareth, EViews Moderator, EViews Jason, EViews Matt
-
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
Might be easiest just to write a loop and calculate the minimum manually.
Re: Retrieving non-zero minimum value of matrix column
yea, thanks for thinking it through with me. This is the best I could do:
(existing matrix called: m1)
(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
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
Re: Retrieving non-zero minimum value of matrix column
Oh that does cut down on things, good idea:) Last question! Let's say I save that as a variable
Is there anyway I can search the original matrix "m1" and return the row+column number for !min?
Code: Select all
!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
Only manually.
Who is online
Users browsing this forum: No registered users and 2 guests
