How can I merge two matrix of 2D points following a specific path?

1 visualizzazione (ultimi 30 giorni)
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 Commenti
Matt J
Matt J il 24 Mar 2022
I suggest attaching a .mat file with the two sets of points, so that we can prototype and demonstrate solutions.
Matt J
Matt J il 24 Mar 2022
Modificato: Matt J il 24 Mar 2022
Will the blue path always consist of only horizontal and vertical lines?

Accedi per commentare.

Risposta accettata

Krishna
Krishna il 5 Ott 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.

Più risposte (0)

Categorie

Scopri di più su Creating and Concatenating Matrices in Help Center e File Exchange

Prodotti


Release

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by