Impact-Site-Verification: dbe48ff9-4514-40fe-8cc0-70131430799e

Search This Blog

Custom Binary Tree in MATLAB


clc
clear all
close all
figure;
pause(2);
for uo=2:5
    clf
a=uo;
connectionx=cell(a,1);
connectiony=cell(a,1);
nodes=2^(a+1)-1;
x=[];
y=[];
temp=0;
for i=1:nodes
    x=[x temp];
    temp=temp+0.5;
end
temp=0;
for i=1:a
    y=[y temp];
    temp=temp-1;
end
tio=0:0.08:2*pi;
wgt=1;
for i=1:1:a
    t=y(i);
    mkdir=[];
    for j=1:wgt
        w=x(j)+0.1*cos(tio);
        tg=t+0.1*sin(tio);
        fill(w,tg,'r');
        hold on;
        if(i==1)
            axis square;
        else
            axis equal;
        end
        pause(0.7);
        connectionx{i}=[connectionx{i} x(j)];
        connectiony{i}=[connectiony{i} y(i)];
    end
    wgt=wgt*2;
end
for i=1:a-1
    x=connectionx{i};
    y=connectiony{i};
    xp=connectionx{i+1};
    yp=connectiony{i+1};
    temp=1;
    for j=1:length(x)
        line([x(j) xp(temp)],[y(j) yp(temp)]);
        temp=temp+1;
        pause(0.3);
        line([x(j) xp(temp)],[y(j) yp(temp)]);
         temp=temp+1;
        hold on;
        pause(0.3);
    end
end
pause(0.7);
end



No comments

Popular Posts