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

1 次查看(过去 30 天)
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 个评论
Matt J
Matt J 2022-3-24
I suggest attaching a .mat file with the two sets of points, so that we can prototype and demonstrate solutions.
Matt J
Matt J 2022-3-24
编辑:Matt J 2022-3-24
Will the blue path always consist of only horizontal and vertical lines?

请先登录,再进行评论。

采纳的回答

Krishna
Krishna 2023-10-5
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 个)

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品


版本

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by