How can I merge two matrix of 2D points following a specific path?
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Matteo Nicoletta
le 24 Mar 2022
Réponse apportée : Krishna
le 5 Oct 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 commentaires
Matt J
le 24 Mar 2022
I suggest attaching a .mat file with the two sets of points, so that we can prototype and demonstrate solutions.
Réponse acceptée
Krishna
le 5 Oct 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 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Creating and Concatenating Matrices dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!