Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 2 minimum numbers
Date: Tue, 25 Dec 2012 15:22:07 +0000 (UTC)
Organization: Comsats Institute of Information Technology
Lines: 84
Message-ID: <kbcgav$5of$1@newscl01ah.mathworks.com>
References: <kb4pbr$c14$1@newscl01ah.mathworks.com> <kb4t6u$eae$1@speranza.aioe.org>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-04-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1356448927 5903 172.30.248.35 (25 Dec 2012 15:22:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 25 Dec 2012 15:22:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 3825107
Xref: news.mathworks.com comp.soft-sys.matlab:785361

Bro I need more help how can I contact you?
"Nasser M. Abbasi" wrote in message <kb4t6u$eae$1@speranza.aioe.org>...
> On 12/22/2012 11:07 AM, Fahad Saleem wrote:
> > Hi I need some help. I have a 25x25 matrix of rand value between 2 & 2.5. I want to
> >do following steps but I am stuck :(
> >
> > 1-  finding minimum nd 2nd minimum number (not row or col just 1 element)
> >in selected 3x3 matrix which is located at
> > [(5,12) (5,13) (5,14);
> >   (6,12) (6,13) (6,14);
> >   (7,12) (7,13) (7,14)] of above matrix. but It must ignore (6,13) and find
> >number in outer 8 locations.
> >
> > 2- from above minimum number it automatically select next matrix of 3x3 on following location
> > [(i-1, j-1)  (i-1, j)  (i-1, j+1);
> >   (i, j-1)     (i, j)     (i, j+1);
> >   (i+1, j-1) (i+1, j)  (i+1, j+1)]
> > * minimum is at location (i,j)
> > and find again minimum and 2nd minimum number
> >
> 
> easy to do if you do not have to worry about running out of the edge of
> the matrix. Because if you find the min at the edge, then in the next
> step, you'll have to take a 3x3 matrix which now goes over the edge.
> 
> I'll let you handle these conditions by adding if statements,
> right now it throws an exception.
> 
> ----------------------------------------
> function driver()
> 
> M=6; A=rand(M);
> row=2; col=2;  %starting index location
> 
> [I,J,B]=getAt(row,col,A);
> [I,J,B]=getAt(I,J,A);
> [I,J,B]=getAt(I,J,A);
> %etc..
> end
> 
> function [I,J,B]=getAt(row,col,A)
> try
>      B=A(row-1:row+1,col-1:col+1);
> catch ME
>      fprintf('opps, fill of the edge! not supported\n');
>      throw(ME)
> end
> 
> tmp    = B(2,2);
> B(2,2) = inf;
> [I,J]  = find(B==min(min(B)));
> B(2,2) = tmp;
> I      = row-(2-I);
> J      = col-(2-J);
> end
> -----------------------------
> 
> on some test I get (starting at location 2,2 in A)
> 
> A =
>      0.6736    0.5985    0.4664    0.1758    0.5631    0.5181
>      0.9130    0.7314    0.4564    0.2949    0.3046    0.7892
>      0.7561    0.8708    0.1278    0.0587    0.7545    0.5712
>      0.1685    0.3334    0.6399    0.0602    0.6711    0.7665
>      0.9640    0.4630    0.8965    0.0267    0.9398    0.9202
>      0.3483    0.1669    0.4274    0.5505    0.4852    0.2103
> 
> B =
>      0.6736    0.5985    0.4664
>      0.9130    0.7314    0.4564
>      0.7561    0.8708    0.1278
> 
> 
> B =
>      0.7314    0.4564    0.2949
>      0.8708    0.1278    0.0587
>      0.3334    0.6399    0.0602
> 
> B =
>      0.4564    0.2949    0.3046
>      0.1278    0.0587    0.7545
>      0.6399    0.0602    0.6711
> 
> --Nasser