order = 6;
numBr = 2^order - 1;     % number of airways
numOrd1 = (numBr+1)/2;

B = reshape(air(3,:,:),[1000,numBr]);
[x,y]=find(summ(3,:)>0);

node1 = zeros(1,numBr);
node2 = zeros(1,numBr);
% e.g. for an order 4: node1 = [1 2 2 3 3 4 4 5 5 6 6 7 7 8 8];
node1(1) = 1;
for i = 1:(numBr-1)/2
node1(2*i:2*i+1) = [i+1 i+1];
end
% e.g. for an order 4: node2 = [2 3 4 5 6 7 8 9 10 11 12 13 14 15 16];
for i = 1:numBr
node2(i) = i+1;
end
ind = zeros(1,numBr);
for i = 1:numBr
ind(i) = i;
end
%     figure,
A=fliplr(B(y(100),:));
figure(1);
G = graph(node1,node2,A);
h=plot(G,'LineWidth',2);
h.EdgeCData=A;
labelnode(h,[node1 node2],'')
% labeledge(h,ind,G.Edges.Weight(ind));
colormap jet
for j = 1:N
    A(j,:,:) = psi1(j,:,:);
%     A1 = reshape(A(j),[12, length(lam1)]);
end


ii = [10 250 750];
for i = 1:length(ii)
figure,
histogram2(summ(:,ii(i)),lam,[50 50],'XBinLimits',[0,1],'YBinLimits',[a1_init b1_init],'FaceColor','flat','Normalization','probability','EdgeColor','none')
% histogram2(flow_sum(:,ii(i)),lam1,[100 100],'XBinLimits',[0,1],'YBinLimits',[a1_init b1_init],'FaceColor','flat','Normalization','probability','ShowEmptyBins','on','EdgeColor','none')
view(2)
title(sprintf('Time {%d} seconds',ii(i)/10))
colorbar
end

numOrd1 = (numBr + 1)/2;
x = cell(1,numOrd1);

y=cell(1,numOrd1);
 for k=1:length(y)
 y{k}=VVDOT(:,k);
 end
%  maxx=(max([y{:}]));
 % % To normalise the flows so that it is between [0,1]
%   for l = 1:length(y)
%       y{l} = y{l}./maxx;
%   end
%   for j=1:length(y)
%       yy{j}= y{j}./max([y{:}]);
%   end
  flow_sum = zeros(1,length(y{1}));
  for i = 1:length(y)
      switch i
          case 1
              neighbour_diff1 = sqrt((y{i} - y{end}).^2 + (y{i} - y{i+1}).^2);
          case length(y)
              neighbour_diff1 = sqrt((y{i} - y{i-1}).^2 + (y{i} - y{1}).^2);
          otherwise
              neighbour_diff1 = sqrt((y{i} - y{i-1}).^2 + (y{i} - y{i+1}).^2);
      end
     flow_sum = flow_sum + neighbour_diff1;
  end
flow_sum=flow_sum./numOrd1;

for j = 1:N
    ii = [10];
    for i = 1:length(ii)
        histogram2(psi1(j,:,ii(i)),lam_dm(j,:),[50 50],'XBinLimits',[0,1],'YBinLimits',[a1_init b1_init],'FaceColor','flat','Normalization','probability','EdgeColor','none')
        % histogram2(flow_sum(:,ii(i)),lam1,[100 100],'XBinLimits',[0,1],'YBinLimits',[a1_init b1_init],'FaceColor','flat','Normalization','probability','ShowEmptyBins','on','EdgeColor','none')
        view(2),hold on,
        title(sprintf('Time {%d} seconds',ii(i)/10))
        colorbar
   end
end
