select a circular region of data and find the average value in that region
10 views (last 30 days)
Show older comments
Hi! I need to select a circular region knowing the center and the radius and find the average value in that region. I tried with the equation of a circle but it doesn't work..what i need to do? Thanks
0 Comments
Answers (1)
KSSV
on 20 Mar 2019
Read about inpolygon.
nx = 100 ; ny = 150 ;
x = linspace(0,1,nx) ;
y = linspace(0,1,ny) ;
[X,Y] = meshgrid(x,y) ;
Z = rand(nx,ny) ;
% Circle
C = rand(1,2) ;
R = 0.3 ;
th = linspace(0,2*pi) ;
xc = C(1)+R*cos(th) ;
yc = C(2)+R*sin(th) ;
% get points inside circle
idx = inpolygon(X(:),Y(:),xc,yc) ;
% GEt mean
iwant = mean(Z(idx')) ;
figure
hold on
pcolor(X,Y,Z')
plot(xc,yc)
plot(X(idx),Y(idx),'.r')
0 Comments
See Also
Categories
Find more on Animation in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!