Main Content

ind2depo

Node index to node depth-position

    Description

    ind2depo is a tree-management utility.

    [d,p] = ind2depo(ord,n) returns, for a tree of order ord, the depths d and positions p (at those depths) for the nodes with indices n.

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

    example

    Examples

    collapse all

    Create a binary wavelet packet tree with three levels.

    Ord = 2;
    Lev = 3;
    T = ntree(Ord,Lev);

    Plot the tree.

    plot(T)

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

    Use the allnodes function to obtain the indices of the nodes in linear order.

    idx = allnodes(T);

    Convert the indices to depth-position format.

    [depth,pos] = ind2depo(Ord,idx);
    table(idx,depth,pos)
    ans=15×3 table
        idx    depth    pos
        ___    _____    ___
    
         0       0       0 
         1       1       0 
         2       1       1 
         3       2       0 
         4       2       1 
         5       2       2 
         6       2       3 
         7       3       0 
         8       3       1 
         9       3       2 
        10       3       3 
        11       3       4 
        12       3       5 
        13       3       6 
        14       3       7 
    
    

    Input Arguments

    collapse all

    Order of a tree, specified as a positive integer.

    Example: A binary tree is a tree of order 2.

    Node indices, specified as a column vector with nonnegative integer entries.

    Output Arguments

    collapse all

    Depths and positions (at those depths) for the nodes with indices n, returned as a pair of column vectors with nonnegative integer entries.

    The values of the depths D and positions N are such that 0≤D and 0≤ PordD-1.

    Note

    If n is a M-by-2 matrix, we have ind2depo(ord,n) = [n(:,1),n(:,2)].

    Version History

    Introduced before R2006a

    See Also