
function [M,K] = makeMK2mod(h,r,branches,Length,rl);

rb = find(branches==0);                 % roots of dendrites
D = length(rb);                         % number of dendrites

% process first dendrite

if 1 < D,
   ind = 1:rb(2)-1;
else
   ind = 1:length(branches);
end

disp([' ind = ' num2str(ind)])

[M,K] = makeMK1(h,r(ind),branches(ind),Length(ind),rl(ind));
figure(1)
spy(M)

% process remaining dendrites

for d = 2:D,

    if d < D
       ind = rb(d):rb(d+1)-1;
    else
       ind = rb(d):length(branches);
    end

    disp([' ind = ' num2str(ind)])

    [Mtemp,Ktemp] = makeMK1(h,r(ind),branches(ind),Length(ind),rl(ind));

    low = size(M,1)+1;
    Nd = size(Mtemp,1);

    disp(['Nd = ' num2str(Nd) ' low = ' num2str(low)]);

    M(1,1) = Mtemp(1,1) + M(1,1);
    M(1,low) = Mtemp(1,2);
    M(low,1) = M(1,low);

    K(1,1) = Ktemp(1,1) + K(1,1);
    K(1,low) = Ktemp(1,2);
    K(low,1) = K(1,low);

    M(low:low+Nd-2,low:low+Nd-2) = Mtemp(2:Nd,2:Nd);
    K(low:low+Nd-2,low:low+Nd-2) = Ktemp(2:Nd,2:Nd);
   
    figure(d)
    spy(M)
    keyboard
   
end
