How can I merge two matrix of 2D points following a specific path?
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Matteo Nicoletta
el 24 de Mzo. de 2022
Respondida: Krishna
el 5 de Oct. de 2023
Hello everyone,
I have a matrix of 2D points that generate the following blue path:
I would like to add new known 2D points (red) that lie on this blue line and create a new matrix with all red and blue points but that follows the same blue path in the picture. In my applications I will have thousands of points so I would like to find a method that possibily doesn't use for-loop for a quite fast computation.
Any suggestions?
Matteo
2 comentarios
Matt J
el 24 de Mzo. de 2022
I suggest attaching a .mat file with the two sets of points, so that we can prototype and demonstrate solutions.
Respuesta aceptada
Krishna
el 5 de Oct. de 2023
Hello Matteo,
I understand that you want to merge two matrices red and blue and you want to merge them according to the blue line described by your graph in shortest time possible.
I think the algorithm described below would work for you.
As matrix blue is already set according to the graph described we do not do any changes to this matrix.
Matrix red is sorted according to the x axis points in ascending order and then points having same x axis are sorted in ascending order of y axis points.
The you just must merge 2 sorted arrays having same x axis point, before moving to the other shortest x axis point.
For example, your blue matrix has points (1,2) (1,5) and your red matrix has points (1,4) (1,7). Now you just must merge two sorted arrays (2,5) and (4,7) respectively before you move on to the next x axis point.
To know more about how to merge two sorted arrays in shortest time and space possible please go through the following documentation:
Hope that helps,
Krishna.
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!