function draw_layers(Electron_LAYER,N,ML,MLthickness)
if nargin==2 || nargin==4
    
else
    errordlg('Incorrect input');
end

L = Electron_LAYER(1).L;
T = Electron_LAYER(1).T;
dL = Electron_LAYER(1).dL;


figure;
hold on
if nargin == 2
    line([-L,L], [0,0],'Color','k','LineWidth',2);
    line([-L,L], [-T,-T],'Color','k','LineWidth',2);
    line([L,L], [0,-T],'Color','k','LineWidth',2);
    
elseif nargin == 4
    line([-L,L], [0,0],'Color','k','LineWidth',2);
    line([-L,L], [-T,-T],'Color','k','LineWidth',2);
    line([L,L], [0,-T],'Color','k','LineWidth',2);
    for k = 1:length(MLthickness)
    csum = cumsum(MLthickness(1:k))*10;
    line([-L,L], [-csum(end),-csum(end)],'Color','k','LineWidth',2);
    end
end


Llayer = length(Electron_LAYER)-2;

L1 = 20;

if ML == 1
N1 = ones(1,20);
else 
    N1 = randi(Llayer,[N,1]);
end
for i = 1:length(N1)
    [m,n] = size(Electron_LAYER(N1(i)).X);
    N2 = randi(m);
    index = Electron_LAYER(N1(i)).Index(N2,1);
    X = Electron_LAYER(N1(i)).X(N2,1:index);
    Y = Electron_LAYER(N1(i)).Y(N2,1:index);
    Z = -(Electron_LAYER(N1(i)).Z(N2,1:index));
    
    if nargin == 4 
        PX = Electron_LAYER(N1(i)).PX(N2,:);
        PY = Electron_LAYER(N1(i)).PY(N2,:);
        PZ = Electron_LAYER(N1(i)).PZ(N2,:);
        if sum(L < PX) == 0
            inds = (L<PX);
        plot(PX(inds==0),-PZ(inds==0),'ro');
        else
        end
    end
        plot([X(1),X(1)],[T,Z(1)],'b--')
        plot(X,Z,'b-')
end
    
    xlabel('dL [nm]')
    ylabel('Hlbka [nm]')
    title('MC Layer')
    xlim([-2*L,2*L])
    ylim([-2*T,T])
    
    