MATLAB Answers

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

3 views (last 30 days)
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);

  4 Comments

Show 1 older comment
muhammad choudhry
muhammad choudhry on 22 Oct 2020
Hi, main code is already attached if u see in the comment above named bestcirclefit.m and for function circlefitbytaubin.m and I also posted text1.txt file with data
per isakson
per isakson on 23 Oct 2020
But you have not told us how to use these three files to reproduce the error, which you have reported!
muhammad choudhry
muhammad choudhry on 23 Oct 2020
Hi,
there was 2 script attached one was best circle fit in which I am calling the function CircleFitByTaubin, which is also attached above please see CircleFitByTaubin.m , I want to use this code to cover most of the points in the circle and estimate the size of that circle and radius.
Thanks

Sign in to comment.

Accepted Answer

per isakson
per isakson on 23 Oct 2020
Edited: per isakson on 23 Oct 2020
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

  5 Comments

Show 2 older comments
Mathieu NOE
Mathieu NOE on 23 Oct 2020
well , the CircleFitByTaubin works as expected:.
the other file (bestcirclefit.m) had the wrong name and was also inconsistent with the supposed name of that function (circlefit.m)
there were some minor stuff like removing unnecessary code
If you edit the files before / after my corrections , you should be able to see what I did
regarding you're experimental data, they are what they are even though they are a bit off from a circle (or the part that you measured has been squeezd ?)
there is nothing that you can do about that... otherwise you want to fit an ellipse ?
muhammad choudhry
muhammad choudhry on 23 Oct 2020
thanks alot for the reply, how to do the ellipse fitting. The major goal is to fit the points to the well defined shape like circle, if you can guide me how to do with the ellipse it will give me a plus point to show in my report that how most of the points are covered through the ellipse.
Thanks alot once again.
per isakson
per isakson on 24 Oct 2020
Search the File Exchange for fit ellipse. There are some submissions, which will help you earn the "plus point".
"to fit the points to the well defined shape" it's the other way round. One fits a model/equation/shape to data points.
And in the column to the right of this page there is an interesting link: Fitting Circles (again) and Ellipses

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!

Translated by