Page 1 of 1

how to know the location of the minimum of a matrix?

Posted: Thu Apr 19, 2012 1:40 am
by tony
I can gain the minimum of a matrix via @min, and I want to know the location of this minimum in the matrix?
Thanks!

Re: how to know the location of the minimum of a matrix?

Posted: Thu Apr 19, 2012 7:41 am
by EViews Gareth
There's nothing built in for that.

Re: how to know the location of the minimum of a matrix?

Posted: Thu Apr 19, 2012 9:19 am
by EViews Glenn
As an aside, the reason it doesn't work is that the index functions return a single element, not a pair.

Having said that, I think the following works. Take the matrix and vec it. Then do the arithmetic to find the relevant indices.

Code: Select all

scalar iid = @imin(@vec(mat01))-1 scalar cid = @floor(iid/@rows(mat01))+1 scalar rid = @mod(iid, @rows(mat01))+1
I usually do this stuff in base-0 so you should do some testing to make sure I've gotten the arithmetic part right. I've done a bit of testing and it looks okay, but no guarantees, especially since I haven't had my caffeine yet this morning.