```Path: news.mathworks.com!not-for-mail
From: "Karl " <karllandheer@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Circular Region in Matrix
Date: Thu, 23 Jun 2011 20:56:04 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 28
Message-ID: <iu0994\$j6\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1308862564 614 172.30.248.38 (23 Jun 2011 20:56:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 23 Jun 2011 20:56:04 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:733477

Hi, I want to average the values in a 616x1216 matrix in rings around a particular point (the centre of the ring, obviously). Currently my program uses a few nested loops to do this but it is very slow as I know MATLAB was not built for iteration. Here is my current code:

j0 = 305;
k0 = 672;
rmin = Rod(RodCounter)-j0+1; %the smallest radius possible is defined by the region directly above the tungsten bar
for r = rmin:NumberOfRows/2; %loop through all possible circles
i = i +1;
%calculate the angle this scatter is taking place at using the
%knowledge that the pixel is 200um by 200um
angles(i) = atan((r*pixelSize)/targetDistance)*180/pi;
t(i) = i;
A(i) = 0.;
C(i) = 0;
for j = 1:NumberOfRows
for k = 1:NumberOfColumns
R_sq = (j-j0)^2 + (k-k0)^2;
if (R_sq > (r-1)^2 & (R_sq <= r^2))
if (j > Rod(RodCounter)) | (j < Rod(1))
A(i) = A(i) + RawImage(j,k);
C(i) = C(i) + 1;
H(i) = A(i)./C(i); %normalize the scatter profile
end
end
end
end
end

I was wondering how I would go about doing this without the loops? Something using mesh grid seems possible but I don't quite understand the function (and have read the help on it)... Or really how it would apply to my case. Anyways thank you very much for your help!
```