Average value of an annulus in a square matrix
Show older comments
I have a square matrix of values and I need to evaluate the average value of an annulus between coordinates r and r+dr and repeat this step from the center of the circle to its radius R. Finally, I want to plot the radial profile of the N values, where N is the number of annuli.

How could I do this in MATLAB? Thank you in advance.
Accepted Answer
More Answers (1)
Jos (10584)
on 6 May 2016
R = 3 ;
M = magic(2*R+1) ;
dr = 1 ;
[ri,ci] = ndgrid(1:(2*R+1))
D = hypot(ri-R-1,ci-R-1)
for k=dr:dr:R
TF = D > (k-dr) & D <= k
tmp = M(TF)
Result(k) = mean(tmp)
end
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!