MATLAB: Recognize the center and diameter of a circle center and diameter of a circle I have a 2D scatter, it is a circle but the center and diameter is not given. I need its center and diameter but as you can see in the figure, there are some noise points around. is there anyway to do this? Best Answer If you have Optimization Toolbox, you can solve this nonlinear least-square problem by simply using lsqnonlin function, like:load('circle_coordinate.mat');x = circle_coordinate(:,1);y = circle_coordinate(:,2);% Solve as nonlinear least-squares problemf = @(a) (x-a(1)).^2 + (y-a(2)).^2 - a(3).^2;a0 = [mean(x),mean(y),max(x)-mean(x)]; af = lsqnonlin(f,a0);% Fittig circletheta = linspace(0,2*pi);xFit = af(1)+af(3)*cos(theta);yFit = af(2)+af(3)*sin(theta);% Visualize the resultfigurescatter(x,y,'.')hold onplot(af(1),af(2),'rx')plot(xFit,yFit,'r-')legend({'Data','Center','Fitting circle'}) Related SolutionsMATLAB: Draw circle with given data. t=0:.1:2*pi;radius = 3;x=radius*cos(t);y=radius*sin(t);plot(x,y)axis square MATLAB: How to draw a circle in a log-log plot Use the FAQ to draw a circle, then exponentiate:http://matlab.wikia.com/wiki/FAQ#How_do_I_create_a_circle.3FxCenter = 12;yCenter = 10;theta = 0 : 0.01 : 2*pi;radius = 5;x = radius * cos(theta) + xCenter;y = radius * sin(theta) + yCenter;xe = exp(x);ye = exp(y);loglog(xe, ye, 'LineWidth', 2);axis square;grid on;hold on;% Draw second circleradius = 3;x = radius * cos(theta) + xCenter;y = radius * sin(theta) + yCenter;xe = exp(x);ye = exp(y);loglog(xe, ye, 'LineWidth', 2); Related QuestionGet data within circular ROIPlot a marker in the center of the circle
Best Answer