具体不做说明,留着以后查找方便。
clear
clc
load ('S.txt');
r=S(:,1);
t=S(:,2);
x=r.*cos(t*pi/180);%转换成直角坐标
y=r.*sin(t*pi/180);%转换成直角坐标
XY=[x,y];
save X44.txt XY -ascii%保存转换后的直角坐标
%%%%%%%%%%%%%%%%曲线方程拟合%%%%%%%%%%%%%%%%%
F=@(p,XY)p(1)*XY(:,1).^2+p(2)*XY(:,1).*XY(:,2)+p(3)*XY(:,2).^2+p(4)*XY(:,1)+p(5)*XY(:,2)+p(6);%椭圆一般方程p0=[1 1 1 1 1 1];
%%%%%%拟合系数,最小二乘法%%%%%%%
p=nlinfit(XY, zeros(siz e(XY,1),1), F, p0);
%调整画图输出样式及大小
s=4800/127;%转换像素
figure('position',[200 200 16*s 16*s]);%确定绘图尺寸
axes('linewidth',3, 'box', 'on', 'FontSiz e',11,'FontName','Times New Roman');
plot(XY(:,1), XY(:,2), 'ro'); hold on;
xmin=min(XY(:, 1)); xmax=max(XY(:, 1));
ymin=min(XY(:, 2)); ymax=max(XY(:, 2));