Creating simple parent index from list of edges and nodes

조회 수: 4 (최근 30일)
Bernard
Bernard 2014년 8월 12일
편집: Yu Jiang 2014년 8월 14일
Hello I am trying to figure out best and fastest way to simplify edge lists into a single index which will be called the parent node index. I have a list of n 3d points and a n-1 x 2 matrix that details the edges that connect between these two points by their index in the list for example a simple 3d segment line would be detailed like xyzpositions =
[23.9880 75.4550 61.0237
23.7692 75.4716 61.0289
23.5496 75.4765 61.0357
23.3299 75.4773 61.0438
23.1102 75.4793 61.0532
22.8906 75.4847 61.0653
22.6715 75.4984 61.0819]
and the list of edges would read
edges = [
1 2
2 3
4 3
4 5
5 6
6 7]
The end result would end up being a n x 1 vector that reads [0 1 2 3 4 5 6] the first point is considered the root and set to 0 so that the arrays will be of equal length. Every method I have been trying, since I haven't perfected it yet uses a lot of for loops and I was hoping there was possibly a more eloquent solution that people already use, The segments are also not always this simple and sometimes two points can connect to the same point so the edges will have same endpoint. thanks!

답변 (1개)

Yu Jiang
Yu Jiang 2014년 8월 14일
편집: Yu Jiang 2014년 8월 14일
Hi Bernard
As far as I know, there is no available tool in MATLAB that can help you create a list of parent nodes directly from the data of edges. There are a function nodepar in the wavelet toolbox (see http://www.mathworks.com/help/wavelet/ref/nodepar.html), and a function parent in the statistics toolbox (see http://www.mathworks.com/help/stats/classregtree.parent.html) that can be used to obtain the parent nodes if the data is first used to construct certain types of trees. However, I think they might not help much in the issue you are facing.
So, I would like to suggest you share some of the code you are currently using. Then, people on this forum may provide useful suggestions on how to improve the efficiency of your code through, for example, appropriate vetorization.
-Yu Jiang

카테고리

Help CenterFile Exchange에서 Graph and Network Algorithms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by