Main Content

nodeasc

Node ascendants

    Description

    nodeasc is a tree-management utility.

    A = nodeasc(T,N) returns the indices of all ascendants of the node N in the tree T.

    example

    A = nodeasc(T,N,"deppos") returns the depths and positions of all ascendants of the node N in the tree T.

    Examples

    collapse all

    Create a binary tree of depth 3.

    t = ntree(2,3);

    Recompose two of the nodes. Plot the tree.

    t = nodejoin(t,5);
    t = nodejoin(t,4);
    fig = plot(t);

    Figure contains an axes object and an object of type uimenu. The axes object with title Tree Decomposition contains 21 objects of type line, text.

    Programmatically, in Node Label, change the selected item from Depth_Position to Index.

    plot(t,"setNodeLabel",fig,"Index")

    Figure contains an axes object and an object of type uimenu. The axes object with title Tree Decomposition contains 21 objects of type line, text.

    Obtain the indices of all ascendants of the node at depth-position (2,2).

    nodeasc(t,[2 2])
    ans = 3×1
    
         5
         2
         0
    
    

    Obtain the depths and positions of all ascendants of the same node.

    nodeasc(t,[2 2],"deppos")
    ans = 3×2
    
         2     2
         1     1
         0     0
    
    

    Input Arguments

    collapse all

    Tree, specified as a dtree, ntree, or wptree object.

    Tree node, specified as a nonnegative integer or a 1-by-2 vector. You can specify the node by either its index or depth and position.

    In the tree, nodes are numbered from left to right and from top to bottom. The root index is 0.

    Data Types: double

    Output Arguments

    collapse all

    Ascendants of the node N, returned as a column vector of node indices or a two-column matrix containing the depths and positions of the descendants.

    • If A is a vector, then A(1) is the index of node N

    • If A is a matrix, the ith row of A contains the depth and position of the ith ascendant. The first row of A is the depth and position of node N.

    Version History

    Introduced before R2006a