필터 지우기
필터 지우기

How should I use the function Circfit ?

조회 수: 18 (최근 30일)
farzad
farzad 2020년 1월 8일
댓글: Adam Danz 2020년 1월 13일
Hi All
How do I use the function Circfit ? the size and class of inputs is not clear

채택된 답변

Adam Danz
Adam Danz 2020년 1월 9일
편집: Adam Danz 2020년 1월 13일
From the help section of that file,
% x,y are column vector where (x(i),y(i)) is a measured point
Their class are double.
They are column vectors of any length but must have the same length between x and y.
Demo
Here's a demo; see the inline comments to understand each step.
First, compute noisy circle coordinates for the demo.
% Create noisy circle coordinates
radius=3;
theta=linspace(0,2*pi,200);
theta(randi(numel(theta),1,190)) = []; % remove some data
x=radius*cos(theta);
y=radius*sin(theta);
% add noise
x = x + (rand(size(x))-0.5)*radius/4;
y = y + (rand(size(y))-0.5)*radius/4;
% Plot it
plot(x,y,'o')
axis equal
Do the fitting but you have to fill in the inputs. The reason I'm not telling you what the inputs should be is not to cause frustration but to get you to think about this. Again, the two inputs are column vectors of your x and y coordinates of each point you're fitting.
% Fit it
[xc,yc,R,a] = circfit(___, ___); % FILL IN THE INPUTS HERE
% [update: here's the solution: [xc,yc,R,a] = circfit(x, y);
Now you can use the outputs to compute the fitted circle and plot it.
% compute circle based on fit params
theta=linspace(0,2*pi,200);
xFit=R*cos(theta) + xc;
yFit=R*sin(theta) + yc;
% add fit
hold on
plot(xc,yc,'rx') % plot circle center
plot(xFit,yFit, 'r-')
  댓글 수: 9
Adam Danz
Adam Danz 2020년 1월 9일
편집: Adam Danz 2020년 1월 10일
Run my example. The x and y variables are vectors and together they are the coordinates of each noisy point along the cirlce. They are the variables you are fitting.
If you are only fitting 3 points, then your x vector will have 3 values (the x value for each point) and your y vector will have 3 values (the y value for each point).
Adam Danz
Adam Danz 2020년 1월 13일
@farzad, in case you still haven't figured it out, I've updated my answer to show what the two inputs should be to circfit().

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by