![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1143975/image.png)
How to calculate the average radius of a boundary in Matlab ?
1 次查看(过去 30 天)
显示 更早的评论
% Example
rng('default')
x = rand(30,1);
y = rand(30,1);
plot(x,y,'.')
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y,0.5);
hold on;
plot(x(k),y(k));
0 个评论
采纳的回答
Image Analyst
2022-10-3
Try this:
% Example
rng('default')
x = rand(30,1);
y = rand(30,1);
plot(x,y,'r.', 'MarkerSize',30)
grid on;
xlim([-0.2 1.2])
ylim([-0.2 1.2])
k = boundary(x,y,0.5);
hold on;
xb = x(k);
yb = y(k);
plot(xb, yb, 'b.-', 'LineWidth', 2, 'MarkerSize',30);
polyin = polyshape(xb, yb);
[xCtr, yCtr] = centroid(polyin)
plot(xCtr, yCtr, 'g+', 'LineWidth', 2, 'MarkerSize',50)
% Get the area
area = polyarea(xb, yb)
% Get the equivalent circular radius
% area = pi * r^2 so r = sqrt(area/pi)
radius = sqrt(area/pi)
% Show circle on graph.
viscircles([xCtr, yCtr], radius); % Requires Image Processing Toolbox.
axis square % So circle looks circular not elliptical.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1143975/image.png)
xCtr =
0.57896610590936
yCtr =
0.522015154012119
area =
0.579388629608274
radius =
0.429447469135391
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!