函数:tree_plot

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_38784454/article/details/79730545
function tree_plot( p ,nodevalues)
%% 参考treeplot函数

[x,y,h]=treelayout(p);
f = find(p~=0);
pp = p(f);
X = [x(f); x(pp); NaN(size(f))];
Y = [y(f); y(pp); NaN(size(f))];

X = X(:);
Y = Y(:);

    n = length(p);
    if n < 500,
        hold on ; 
        plot (x, y, 'ro', X, Y, 'r-');
        nodesize = length(x);
        for i=1:nodesize
%            text(x(i)+0.01,y(i),['node' num2str(i)]); 
            text(x(i)+0.01,y(i),nodevalues{1,i}); 
        end
        hold off;
    else
        plot (X, Y, 'r-');
    end;

xlabel(['height = ' int2str(h)]);
axis([0 1 0 1]);

end

猜你喜欢

转载自blog.csdn.net/qq_38784454/article/details/79730545