MATLAB: Index exceeds the number of array elements (1). Error coming in the code below

arraycircle fittingcurve fittingindex

Hi,
I am using one of the matlab function called CircleFitByTaubin but I am stuck on one of the line as shown in the error below and not sure how to correct this? If anyone can help here? I have attached the code, function and data here.
Error:
Index exceeds the number of array elements (1).
Error in CircleFitByTaubin (line 25)
Yi = XY(i,2) – centroid(2); % centering data
Error in circlefitting (line 9)
Par = CircleFitByTaubin(P);

Best Answer

I cannot reproduce (on R2018b) the error that you report:
Index exceeds the number of array elements (1).
Error in CircleFitByTaubin (line 25)
Yi = XY(i,2) - centroid(2); % centering data
Error in circlefitting (line 9)
Par = CircleFitByTaubin(P);
You have not provided the mfunction, circlefitting. There is no call to CircleFitByTaubin in bestcirclefit.m. The mfile, bestcirclefit.m, has an syntax error and isn't possible to run.
CircleFitByTaubin works as expected:
%%

XY = dlmread('test1.txt','\t',0,0);
%%
par = CircleFitByTaubin(XY);
and returns
>> par
par =
0.41541 0.30058 0.028124