How can I merge two matrix of 2D points following a specific path?
3 次查看(过去 30 天)
显示 更早的评论
Hello everyone,
I have a matrix of 2D points that generate the following blue path:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/939904/image.jpeg)
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
2022-3-24
I suggest attaching a .mat file with the two sets of points, so that we can prototype and demonstrate solutions.
采纳的回答
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!