```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: 2 minimum numbers
Date: Sat, 22 Dec 2012 18:37:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 18
Message-ID: <kb4ukj\$sbb\$1@newscl01ah.mathworks.com>
References: <kb4pbr\$c14\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-03-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1356201428 29035 172.30.248.48 (22 Dec 2012 18:37:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 22 Dec 2012 18:37:08 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:785271

"Fahad Saleem" wrote in message <kb4pbr\$c14\$1@newscl01ah.mathworks.com>...
> 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 :(
>.....
- - - - - - - - - - -
If you intend this to be an iterative procedure, as Nasser warns, you will need to modify it to allow for running into an edge.  Also you need to do something about getting stuck in an infinite repeating iteration - that is, traveling around in some repeating "minimum" circuit within your matrix.

% Initial values
n = 25;
a = rand(n);
ix = 6; jx = 13;
r = [-1  0  1  1  1  0 -1 -1];
c = [-1 -1 -1  0  1  1  1  0];

% The iteration
[~,k] = min(a(r+ix+n*(c-1+jx)));
ix = ix + r(k); jx = jx + c(k);

Roger Stafford
```