I have unordered coordinates and when i order it by doing th following,
contorno = readtable('HJ_00-01.xlsx');
contx = table2array(contorno(:,1));
conty = table2array(contorno(:,2));
cx = mean(contx);
cy = mean(conty);
a = atan2(conty - cy, contx - cx);
[~, order] = sort(a);
reorderedx = contx(order);
reorderedy = conty(order);
When I plot, this is what i get
plot(reorderedx, reorderedy)
How do I get a continuous "smoth" line plot without the spikes that are present in the figure.
What is the best way to reorder my data?

 Respuesta aceptada

Bruno Luong
Bruno Luong el 23 de Nov. de 2018
Solve it as Traveling SalesMan PB: Use this FEX
contorno = readtable('HJ_00-01.xlsx');
contx = table2array(contorno(:,1));
conty = table2array(contorno(:,2));
userConfig = struct('xy',[contx(:) conty(:)]);
resultStruct = tsp_nn(userConfig);

Más respuestas (2)

Cris LaPierre
Cris LaPierre el 23 de Nov. de 2018

2 votos

This is a non-trivial problem, as I'm sure you've discovered. I'm wondering if you can find something useful in this traveling salesman example problem.
Image Analyst
Image Analyst el 23 de Nov. de 2018

0 votos

One way is to sort things angulalry. Compute the center, then compute the angles of each point from the center, then use both outputs of sort(). Easy, but let us know if you can't do it.

4 comentarios

Bruno Luong
Bruno Luong el 23 de Nov. de 2018
@IA: But he just did that, don't you see his code?
Image Analyst
Image Analyst el 23 de Nov. de 2018
Editada: Image Analyst el 23 de Nov. de 2018
Honestly I didn't look at the code much. The plot does not look like the points are all going in the same angular direction. There is a lot of backtracking going on.
Bruno Luong
Bruno Luong el 23 de Nov. de 2018
Editada: Bruno Luong el 23 de Nov. de 2018
Of course it does, depending where the center is (I can see very well where it's located approximatively, up north there), which is in turn depend on the density of the point on the boundary.
In anycase this kind of method (angle sorting) bounds to fail for such complicated boundary.
Image Analyst
Image Analyst el 23 de Nov. de 2018
Yes, when I ran the code, and plotted the centroid, it shows the centroid is not where you'd have thought at first. For what it's worth, I also tried the boundary() function. I agree the TSP solution seems to be best. I'm voting for that.

Iniciar sesión para comentar.

Preguntada:

el 23 de Nov. de 2018

Comentada:

el 23 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by