```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Getting the min and max of a matrix
Date: Sun, 1 Mar 2009 06:24:02 +0000 (UTC)
Organization: Battelle Energy Alliance (INL)
Lines: 23
Message-ID: <god9m2\$hus\$1@fred.mathworks.com>
References: <goc1a7\$g2q\$1@fred.mathworks.com> <goc2dp\$re1\$1@fred.mathworks.com> <goc5sd\$bvd\$1@fred.mathworks.com> <goc73p\$11l\$1@fred.mathworks.com> <goc7mh\$8er\$1@fred.mathworks.com> <goc899\$h64\$1@fred.mathworks.com> <gocuc5\$mmf\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1235888642 18396 172.30.248.38 (1 Mar 2009 06:24:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sun, 1 Mar 2009 06:24:02 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:521622

You don't have to copy all the matrix a, just the rows of interest.  Otherwise, this finds the minimum for a without the index in the first row of b.  That is if you never have negative infs in your matrix a.

a=[
Inf 26 Inf 21 24
25 Inf Inf 24 22
23 27 Inf 22 25
28 20 Inf Inf 21
22 24 Inf 23 Inf
];
b=[
1 4 3
4 1 2
];

min(a(b(1,1),[1:b(1,2)-1, b(1,2)+1:end]))

If all of the infs are positive this should work whatever the rest of the values.
I don't see any way of finding the max without first dealing with the infs.  One approach is to copy the fourth row:

ar = a(b(2,1),:).*isfinite(a(b(2,1),:))
max(ar(1,[1:b(2,2)-1, b(2,2)+1:end]))
```