怎么用Matlab实现椭圆拟合?

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/02 12:28:57
怎么用Matlab实现椭圆拟合?

怎么用Matlab实现椭圆拟合?
怎么用Matlab实现椭圆拟合?

怎么用Matlab实现椭圆拟合?
以下为matlab采用最小二乘法的椭圆拟合程序:
function a = fitellipse(X,Y)
% FITELLIPSE Least-squares fit of ellipse to 2D points.
% A = FITELLIPSE(X,Y) returns the parameters of the best-fit
% ellipse to 2D points (X,Y).
% The returned vector A contains the center, radii, and orientation
% of the ellipse, stored as (Cx, Cy, Rx, Ry, theta_radians)
%
% Example: Run fitellipse without any arguments to get a demo
if nargin == 0
% Create an ellipse
t = linspace(0,2);
Rx = 300
Ry = 200
Cx = 250
Cy = 150
Rotation = .4 % Radians
x = Rx * cos(t);
y = Ry * sin(t);
nx = x*cos(Rotation)-y*sin(Rotation) + Cx;
ny = x*sin(Rotation)+y*cos(Rotation) + Cy;
% Draw it
plot(nx,ny,'o');
% Fit it
fitellipse(nx,ny)
% Note it returns (Rotation - pi/2) and swapped radii, this is fine.
return
end
% normalize data
mx = mean(X);
my = mean(Y);
sx = (max(X)-min(X))/2;
sy = (max(Y)-min(Y))/2;
x = (X-mx)/sx;
y = (Y-my)/sy;
% Force to column vectors
x = x(:);
y = y(:);
% Build design matrix
D = [ x.*x x.*y y.*y x y ones(size(x)) ];
% Build scatter matrix
S = D'*D;
% Build 6x6 constraint matrix
C(6,6) = 0; C(1,3) = -2; C(2,2) = 1; C(3,1) = -2;
% Solve eigensystem
[gevec, geval] = eig(S,C);
% Find the negative eigenvalue
I = find(real(diag(geval)) < 1e-8 & ~isinf(diag(geval)));
% Extract eigenvector corresponding to negative eigenvalue
A = real(gevec(:,I));
% unnormalize
par = [
A(1)*sy*sy, ...
A(2)*sx*sy, ...
A(3)*sx*sx, ...
-2*A(1)*sy*sy*mx - A(2)*sx*sy*my + A(4)*sx*sy*sy, ...
-A(2)*sx*sy*mx - 2*A(3)*sx*sx*my + A(5)*sx*sx*sy, ...
A(1)*sy*sy*mx*mx + A(2)*sx*sy*mx*my + A(3)*sx*sx*my*my ...
- A(4)*sx*sy*sy*mx - A(5)*sx*sx*sy*my ...
+ A(6)*sx*sx*sy*sy ...
]';
% Convert to geometric radii, and centers
thetarad = 0.5*atan2(par(2),par(1) - par(3));
cost = cos(thetarad);
sint = sin(thetarad);
sin_squared = sint.*sint;
cos_squared = cost.*cost;
cos_sin = sint .* cost;
Ao = par(6);
Au = par(4) .* cost + par(5) .* sint;
Av = - par(4) .* sint + par(5) .* cost;
Auu = par(1) .* cos_squared + par(3) .* sin_squared + par(2) .* cos_sin;
Avv = par(1) .* sin_squared + par(3) .* cos_squared - par(2) .* cos_sin;
% ROTATED = [Ao Au Av Auu Avv]
tuCentre = - Au./(2.*Auu);
tvCentre = - Av./(2.*Avv);
wCentre = Ao - Auu.*tuCentre.*tuCentre - Avv.*tvCentre.*tvCentre;
uCentre = tuCentre .* cost - tvCentre .* sint;
vCentre = tuCentre .* sint + tvCentre .* cost;
Ru = -wCentre./Auu;
Rv = -wCentre./Avv;
Ru = sqrt(abs(Ru)).*sign(Ru);
Rv = sqrt(abs(Rv)).*sign(Rv);
a = [uCentre, vCentre, Ru, Rv, thetarad];

怎么用Matlab实现椭圆拟合? 怎么用matlab代码拟合椭圆?离散点拟合椭圆,求matlab代码,要确定可以用的! 请问最小二乘法圆拟合求半径 matlab编程实现三维数据怎么,用最小二乘法圆拟合,并求出半径? 最小二乘法拟合椭圆怎么求,最好matlab代码 matlab 怎样实现拉格朗日插值拟合? 我想问matlab椭圆拟合的程序是什么?能不能直接对标准形式进行拟合?怎么求出拟合误差? 怎么用matlab拟合反比例函数 编写MATLAB程序实现多项式拟合 Matlab中如何拟合椭圆现有一组数据,要用椭圆拟合他们,并得到拟合后椭圆的相关数据信息Matlab中有直接可调用的函数吗?没有的话, 怎么用matlab进行数据拟合然后计算误差 怎么用matlab拟合函数,最好是三元的多项式 用matlab拟合函数求系数,只有一个系数该怎么拟合 用matlab 对一组数据进行拟合后,怎么直接显示拟合函数的图像? matlab数据拟合问题我想要拟合y=a*x1+b*x2+c形式的曲线,用matlab如何实现? 给出一些椭圆上离散的点的横纵坐标,怎么用matlab拟合出椭圆方程比如这些点是(1,0) (-1,0) (0,2 ) (0,-2) matlab能处理多参数线性拟合么?y=ax1+bx2+cx3+dx4+e之类的.是用polyfit实现么?用矩阵运算计算系数矩阵?具体怎么实现?最好能给个小例子看看? 在用matlab进行数值拟合时,在知道x,y两组数据后,怎样实现数据的拟合 除了用polyfit 函数外那自己编写程序怎样来实现拟合 没学过matlab,但急需拟合函数,怎么弄得啊?怎样用matlab实现θ=arcsin[(Vout-1650)/800]的拟合啊?没学过matlab,但急需合成,那位高手可以指教下吧?