Borrar filtros
Borrar filtros

How to fix this error “Index exceeds the number of array elements (57)” while using minboundquad function

1 visualización (últimos 30 días)
%x = randn(50,1);
%y = randn(50,1);
[qx,qy] = minboundquad(x,y);
Error shown is
The function is working for randomly generated points but not working for my pointset.
Can someone please help me solve this? This is the function minboundquad

Respuesta aceptada

Gowtham HariHara
Gowtham HariHara el 26 de Mayo de 2021
Editada: Gowtham HariHara el 26 de Mayo de 2021
Along with the modification suggested by @Sindhu Karri and Modifying another line in minboundquad.m from
if ( A_i < quadarea)
if (( A_i < quadarea)&& all(abs([qxi qyi]) < 1e15))
resolves the issue.

Más respuestas (3)

Sindhu Karri
Sindhu Karri el 11 de Mayo de 2021
Modifying the line in minboundquad.m from
edges = convhull(x,y);
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 comentarios
Gowtham HariHara
Gowtham HariHara el 14 de Mayo de 2021
@Sindhu Karri As per your suggestion, I contacted the author of the toolbox for further clarification. But, unfortunately, due to some confusions, we could not solve it for different pointset.
If possible, will you please help me to solve this? It'll be really helpful. I attached the pointset.
Gowtham HariHara
Gowtham HariHara el 25 de Mayo de 2021
@Sindhu Karri I tried alot to find what the error might be. I could not find. Will you help me find the error?

Iniciar sesión para comentar.

John D'Errico
John D'Errico el 11 de Mayo de 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.
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));
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);
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 comentario
Gowtham HariHara
Gowtham HariHara el 12 de Mayo de 2021
Editada: Gowtham HariHara el 12 de Mayo de 2021
@John D'Errico Thank you so much sir for your time and reply.
Though the modification in the function worked for the above pointset, unfortunately it did not work for some of the other cases like point-set2_this. The result for the linked pointset is like this.
Will you please help me find the possible error? This is the pointset

Iniciar sesión para comentar.

AMO el 29 de Mayo de 2021
Editada: AMO el 29 de Mayo de 2021
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.




Community Treasure Hunt

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

Start Hunting!

Translated by