try_circ_fitgai.m

来自「这是用最小二乘法编写的程序」· M 代码 · 共 77 行

M
77
字号
% 写入一组数据x,y
% 画出这些数据在坐标面的图形
% 用circfit拟合出圆心和半径
% 
% 圆心(xc,yc) 


th = linspace(0,2*pi,200)';

 x = [
3.105240816627634
3.842272217109386
4.525109412571643
4.96516054383299
5.430063015752501
5.471623959289557
5.267638746605347
4.784779535235192
4.181448065548226
3.414805511294115
2.611546942222702
1.76837538915662
1.190624549998018
0.734772000988176
0.529409901608607
0.573251513927203
0.931228586186639
1.553030706664068
2.144382787294432
2.955908335236294
];

  y = [
0.483220848230414
0.313229622700572
-0.049357854133657
-0.631477912114776
-1.383100990158417
-2.273182533554851
-3.029403407318204
-3.668280076348937
-4.210646067620194
-4.45883747500716
-4.418508513095978
-4.255411054624004
-3.696381518302045
-2.999380429206509
-2.255829847208239
-1.487374575402619
-0.609257281218404
-0.024500186718258
0.390606916543935
0.510084467937848
];

  
   plot(x,y,'o'), title(' measured points')
   pause(1)
   
   % 由以上数据拟合圆
   [xc,yc,Re,a] = circfit(x,y);
      xe = Re*cos(th)+xc; ye = Re*sin(th)+yc;
 
     plot(x,y,'o',[xe;xe(1)],[ye;ye(1)],'-.'),
     title(' measured fitted and true circles')
      legend('measured','fitted')
      text(xc-Re*0.9,yc,sprintf('center (%g , %g );  R=%g',xc,yc,Re))
     xlabel x, ylabel y 
     axis equal
     
     

   
  


⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?