```Path: news.mathworks.com!newsfeed-00.mathworks.com!news.kjsl.com!news.stack.nl!aioe.org!.POSTED!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 2 minimum numbers
Date: Sat, 22 Dec 2012 11:45:44 -0600
Organization: Aioe.org NNTP Server
Lines: 41
References: <kb4pbr\$c14\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: JKSFeTjoA7DiGvggDLtceQ.user.speranza.aioe.org
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@aioe.org
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.28) Gecko/20120306 Thunderbird/3.1.20
X-Notice: Filtered by postfilter v. 0.8.2
Xref: news.mathworks.com comp.soft-sys.matlab:785269

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

Simple enough...multiple options, for such a small subset it's probably
simpler to just use sort() and select the first two elements rather than
do the min() and reduction.

To skip the center location simply replace the x(i,j)=NaN; for
i,j==desired location.

Base step (you'll want to generalize, of course)...

i=6; j=13;
xtarg=x(i-1:i+1,j-1:j+1);
xtarg(2,2)=nan;
[xmin,idx]=sort(xtarg(:));

Now you've got the info for the two min values (xmin(1:2) and the
locations in the idx vector from which to find the location for the new i,j)

Salt to suit...

--

```