Add node numbers / get node locations from MATLAB tree

I work with the MATLAB treeplot function, but it seems to provide surprisingly little functionality and / or extensibility to the graphs.

I draw a tree like this:

tree = [0 1 2 2 2 2 2 1 8 8 1 11 11 1 14]; treeplot(tree) 

Donation: enter image description here

What I would like to do is add annotations or tags to specific nodes. A good starter would be to add node numbers to each node, as in the example from the help file:

enter image description here

As they claim, though:

These indices are shown for illustrative purposes only; they are not part of the treeplot output.

Is there a way to get the location of the constructed nodes, or at least to build the node numbers? I could not find any FEX suggestions with more advanced tree charts.

Ultimately, I would like to build small snapshots in nodes (using the methods from the answers to the previous question ).

+4
source share
2 answers

To get the position of nodes, use treelayout

 [x,y]=treelayout(tree); 

The vectors x and y provide you with positions that you can then use to build images in nodes.

+3
source

This will help you create a tagged tree: (You supply "treeVec".)

 treeplot(treeVec); count = size(treeVec,2); [x,y] = treelayout(treeVec); x = x'; y = y'; name1 = cellstr(num2str((1:count)')); text(x(:,1), y(:,1), name1, 'VerticalAlignment','bottom','HorizontalAlignment','right') title({'Level Lines'},'FontSize',12,'FontName','Times New Roman'); 

With your sample input this gives enter image description here

+8
source

Source: https://habr.com/ru/post/1340601/


All Articles