Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Getting the min and max of a matrix
Date: Sat, 28 Feb 2009 18:55:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <goc1a7$g2q$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1235847304 16474 172.30.248.37 (28 Feb 2009 18:55:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 28 Feb 2009 18:55:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1551459
Xref: news.mathworks.com comp.soft-sys.matlab:521562


Hi all,

My question here is how to find the maximum and minimum of a row in a matrix but with a small constraint. Assume we have a matrix,

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]

Now I want to find the minimum of row 1 in matrix A. It would be 21, however I want to see matrix B first 2 columns and can see that first row has (1 4) and second row (4 1). Since 21 is in position (1,4) then that cannot be the minimum, so I have to find the minimum not including that one, so it would be 24 as it is not in matrix B.

Same thing for maximum, without counting the Inf. If I was to find the max finite number in row 4 of matrix A it is 28, however that is in position (4,1) and (4 1) is in matrix B so the max would actually be 21.

I hope I made myself clear.

I was finding the max and min without the constraint of matrix B the following way,

Minimum = min(A(1,:));

m = A(4,:)
Maximum = max(max(h(isfinite(h)),1));

Thank you so much!