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: Sat, 28 Feb 2009 20:54:01 +0000 (UTC)
Organization: Universit&#228;tsSpital Z&#252;rich
Lines: 39
Message-ID: <goc899$h5h$1@fred.mathworks.com>
References: <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 1235854441 17585 172.30.248.37 (28 Feb 2009 20:54:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 28 Feb 2009 20:54:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 11
Xref: news.mathworks.com comp.soft-sys.matlab:521583


"Diego Zegarra"
> 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...

one of the solutions

     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
     ];
     ix=sub2ind(size(a),b(:,1),b(:,2));
     a(ix)=inf;
     disp(a);
%{
          Inf    26   Inf    Inf    24
           25   Inf   Inf    24    22
           23    27   Inf    22    25
          Inf    20   Inf   Inf    21
           22    24   Inf    23   Inf

%}
% now look for the min/max in the new A...

us