making combinations from each leaf to parent node in Matlab

Hello, I have to make all combinations from a tree, starting from parent node and ends at the last leaf nodes. The depth of all leaf nodes is same. I don't understand how can i get such a combination... starting from parent node ending to the leaf node.
Can anyone help please.

5 件のコメント

Guillaume
Guillaume 2018 年 6 月 19 日
Please use Comment on this question instead of starting new answers.
How is your tree stored in matlab?
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 6 月 20 日
編集済み: Walter Roberson 2018 年 6 月 20 日
you can see the code and picture attached to this comment, although the picture does not show the complete tree but just to give you an idea, thanks for your kind response, i hope you can help me
t = tree(Ap1)
%i=2;
for i=1:length(C{1})
[t node(i)] = t.addnode(1, C{1}(i,:))
disp(t.tostring)
end
%i=1;
disp(t.tostring)
jjj=1
for x=2:length(C)
for y=1:length(C{x})
jjj=jjj+1
for z=1:length(C{x}{y})
[t node(i)] = t.addnode(jjj, C{x}{y}(z,:))
i=i+1;
disp(t.tostring)
end
end
end
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 6 月 20 日
編集済み: Sohaib Bin Altaf 2018 年 6 月 20 日
what i require is in the attached picture, all the combinations like the one shown
Guillaume
Guillaume 2018 年 6 月 20 日
Where does the tree class come form? As far as I know there's no such thing in any matlab toolbox.
Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 6 月 21 日
I followed this article, i was able to construct my required tree but unable to extract the branches which i need,

サインインしてコメントする。

回答 (1 件)

Steven Lord
Steven Lord 2018 年 6 月 21 日

0 投票

Consider building your tree as a graph. You could create the adjacency matrix or the edge lists as shown on that page or you could start with an empty graph and use addedge to add edges (either one at a time, or from a parent to each of its children, or in some other grouping.)
As you add edges, you can plot the resulting graph to see how it is growing. The rmedge function may help if you accidentally add the wrong edge.

1 件のコメント

Sohaib Bin Altaf
Sohaib Bin Altaf 2018 年 6 月 22 日
thanks a lot for your suggestion, i will try graphs this time. I hope it solves my problem.

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeMATLAB についてさらに検索

質問済み:

2018 年 6 月 19 日

コメント済み:

2018 年 6 月 22 日

Community Treasure Hunt

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

Start Hunting!

Translated by