How to fix this error “Index exceeds the number of array elements (57)” while using minboundquad function
2 views (last 30 days)
Show older comments
%x = randn(50,1);
%y = randn(50,1);
points=importdata('points1.txt');
x=points(:,1);
y=points(:,2);
[qx,qy] = minboundquad(x,y);
plot(x,y,'ro',qx,qy,'b-')
Error shown is
0 Comments
Accepted Answer
More Answers (3)
Sindhu Karri
on 11 May 2021
Hii,
Modifying the line in minboundquad.m from
edges = convhull(x,y);
to
edges = convhull(x,y,'Simplify',true);
resolves the issue.
Refer to below link for further information on 'Simplify' parameter
minboundquad is one of the several submissions in MATLAB File Exchange on MATLAB Central which is a forum for our product users to interact, exchange information and knowledge, without MathWorks involvement. Feel free to contact the author of this submission directly for specific questions about any further clarification on implementation.
3 Comments
John D'Errico
on 11 May 2021
That code was written so long ago, I forgot I ever wrote it. But also, it was written in the days when the convex hull and triangulation tools in MATLAB were far less mature/sophisticated than they are now.
If I look at your dataset, it is just a huge number of points that all fall on a nice integer lattice. You probably extracted them as pixels from an image.
plot(xy(:,1),xy(:,2),'.')
All of the codes in that toolbox generally first took the convex hull of the data. Anything inside the convex hull is meaningfless in terms of a bounding polygon anyway. It dramatically reduces the problem, since it needs only to work with the edges of the convex hull.
T = convhull(xy(:,1),xy(:,2));
plot(xy(T,1),xy(T,2),'-o')
The problem arises since your data lives purely on an integer lattice. And that means that at least a few of those edges were collinear edges in the simple convex hull. In turn, that got the code confused.
The simple fix is to use what was suggested by @Sindhu Karri
T2 = convhull(x,y,'Simplify',true);
plot(xy(T2,1),xy(T2,2),'r-s')
As you can see here, the simplify option was smart to replace those multiple collinear edges with a single edge. That resolves the problem in the code, and it will make the code run faster too.
I must post new versions of the codes in that toolbox.
1 Comment
AMO
on 29 May 2021
Edited: AMO
on 29 May 2021
Hi,
In minboundquad.m line 115, when removing consecutive edges that have the same angles the variable nedges is not updated. so adding
nedges = size(edges,1);
after line 122 seems to solve the problem. But I am not sure if this is the right way.
0 Comments
See Also
Categories
Find more on Bar Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!