function [ElectronFC] = MC_FilledCapsle(Electron1,Electron2,R1,R2,Gula,TH_max, Probe_diam)
R1 = R1*10; R2 = R2*10;
Probe_diam = Probe_diam*10;

Thd1 = 0.034; % 34 mrad
Thd2 = 0.039; % 39 mrad
Thd3 = 0.054; % 54 mrad

% ,,Gula'' - je Electron1 vysledok simulacie na guli ??? 'A' - ano, 'N' - nie
if Gula == 'A'
    ElectronOUT = Electron1;
elseif Gula == 'N'
    [ElectronOUT] = MC_sphere(Electron1, TH_max, Probe_diam, 1,1,1,0,R1/10,1,1);
    %   [ElectronOUT] = MC_sphere(Electron, TH_max, Probe_diam, TH_calc,Probe_calc,A,focus,R,dR,MultiCapsle)
else
    errordlg('Gula must be "A" or "N"!  ');
end

[s1,s2] = size(ElectronOUT);
ElectronIN = Electron2;
h = waitbar(0,'MC FilledCapsle ...');
for i = 1:s2
    [v1,v2] = size(ElectronOUT(i).X);
    waitbar(i/s2) 
    % priprava novej struktury na ukladanie
    ElectronFC(i).X  = zeros(v1,round(v2*2.5));
    ElectronFC(i).Y  = zeros(v1,round(v2*2.5));
    ElectronFC(i).Z  = zeros(v1,round(v2*2.5));
    ElectronFC(i).Th = zeros(v1,round(v2*2.5));
    ElectronFC(i).Ps = zeros(v1,round(v2*2.5));
    ElectronFC(i).dE = zeros(v1,round(v2*2.5));
    ElectronFC(i).SE = zeros(v1,round(v2*2.5));
    ElectronFC(i).Zcalc = zeros(v1,round(v2*2.5));
    ElectronFC(i).USE = zeros(v1,1);
    ElectronFC(i).SCE = zeros(v1,1);
    ElectronFC(i).BSE = zeros(v1,1);
    ElectronFC(i).BF = zeros(v1,1);
    ElectronFC(i).DF = zeros(v1,1);
    ElectronFC(i).HAADF = zeros(v1,1);
    ElectronFC(i).THETA = zeros(v1,1);
   
    % urcenie prieniku dat vonkajsej gule s vnutornou
    Prieniky = sqrt(ElectronOUT(i).X.^2 + ElectronOUT(i).Y.^2 + ElectronOUT(i).Zcalc.^2);
%     Prieniky = sqrt(ElectronOUT(i).X.^2 + ElectronOUT(i).Y.^2 + ElectronOUT(i).Z.^2);
    Prieniky(Prieniky>=R2) = 0;
    Prieniky(Prieniky>0)= 1;
    
    %najdene priesecniky pre kazdy elektron
    % priesecnik PRED prechodom
    [Z1a,IndZ1] = max(Prieniky,[],2);  % pozor tymto zrusim BSEcka
%     [s1,s2] = size(Zi);
    v = (1:v1)';
    IndZ1 = IndZ1-1;
    inds = (IndZ1-1).*v1 + v;
    X1 = zeros(size(IndZ1));
    Y1 = zeros(size(IndZ1));
    Z1 = zeros(size(IndZ1));
    Th1 = zeros(size(IndZ1));
    Zcalc1 = zeros(size(IndZ1));
    
    X1(inds>0) = ElectronOUT(i).X(inds(inds>0));
    Y1(inds>0) = ElectronOUT(i).Y(inds(inds>0));
    Th1(inds>0) = ElectronOUT(i).Th(inds(inds>0));
    Z1(inds>0) = ElectronOUT(i).Z(inds(inds>0)); 
    Zcalc1(inds>0) = ElectronOUT(i).Zcalc(inds(inds>0));
    inds1 = find(Prieniky(:,1)==1);
    X1(inds1) = ElectronOUT(i).Xn(inds1);
    Y1(inds1) = ElectronOUT(i).Yn(inds1);
    Z1(inds1) = ElectronOUT(i).Zn(inds1);
%     Zcalc1(inds1) = R1 - ElectronOUT(i).Zn(inds1);
    Zcalc1(inds1) = ElectronOUT(i).Zn(inds1);
    Th1(inds1) = 0;
    % priesecnik ZA prechodom
    IndZ2 = IndZ1 + 1;
    inds2 = (IndZ2-1).*v1 + v;
%     inds2(Prieniky(:,1)==1) = inds2(Prieniky(:,1)==1)-v1;
    X2  = ElectronOUT(i).X(inds2);
    Y2  = ElectronOUT(i).Y(inds2);
    Th2 = ElectronOUT(i).Th(inds2);
    Z2  = ElectronOUT(i).Z(inds2);
    Zcalc2 = ElectronOUT(i).Zcalc(inds2);
        
    BezPrieniku = find(sum(Prieniky,2)==0); % hladanie nul v prienikoch (nieje prienik nepocita sa)
    if isempty(BezPrieniku)==0
        for k = 1:length(BezPrieniku)  % ulozenie dat bez prieniku
            kk = BezPrieniku(k);
            ElectronFC(i).X(kk,1:v2)     = ElectronOUT(i).X(kk,1:v2);
            ElectronFC(i).Y(kk,1:v2)     = ElectronOUT(i).Y(kk,1:v2);
            ElectronFC(i).Z(kk,1:v2)     = ElectronOUT(i).Z(kk,1:v2);
            ElectronFC(i).Th(kk,1:v2)    = ElectronOUT(i).Th(kk,1:v2);
            ElectronFC(i).Ps(kk,1:v2)    = ElectronOUT(i).Ps(kk,1:v2);
            ElectronFC(i).dE(kk,1:v2)    = ElectronOUT(i).dE(kk,1:v2);
            ElectronFC(i).SE(kk,1:v2)    = ElectronOUT(i).SE(kk,1:v2);
            ElectronFC(i).Zcalc(kk,1:v2) = ElectronOUT(i).Zcalc(kk,1:v2);
            ElectronFC(i).Xn(kk,1) = ElectronOUT(i).Xn(kk,1);
            ElectronFC(i).Yn(kk,1) = ElectronOUT(i).Yn(kk,1);
            ElectronFC(i).Zn(kk,1) = ElectronOUT(i).Zn(kk,1);
            ElectronFC(i).IndexDraw(kk,1) = 0;
            
            ElectronFC(i).USE(kk,1) = 1;
            ElectronFC(i).SCE(kk,1) = 0;
            ElectronFC(i).BSE(kk,1) = 0;
            ElectronFC(i).THETA(kk,1) = ElectronOUT(i).iTH_X(kk,1);
            THETA = abs(ElectronFC(i).THETA(kk,1));
            if THETA <= Thd1
                ElectronFC(i).BF(kk,1) = 1;
                ElectronFC(i).DF(kk,1) = 0;
                ElectronFC(i).HAADF(kk,1) = 0;
            elseif THETA > Thd1 && THETA <= Thd3
                ElectronFC(i).DF(kk,1) = 1;
                ElectronFC(i).BF(kk,1) = 0;
                ElectronFC(i).HAADF(kk,1) = 0;
            else
                ElectronFC(i).HAADF(kk,1) = 1;
                ElectronFC(i).DF(kk,1) = 0;
                ElectronFC(i).BF(kk,1) = 0;
            end
        
        end
        % nastavenie ukladania pre dalasi cyklus
        delkaCyklu = (v1-length(BezPrieniku));
        pom = (1:v1)';
        pom(BezPrieniku) = 0;
        Sprienikom = find(pom>0);
    else
        delkaCyklu = v1;
        Sprienikom = 1:v1;
    end
    
    
    for j = 1:delkaCyklu  % pocet radku = pocet elektronu pre aktualny posun s prienikom dovnutrakapsle
        jj = Sprienikom(j);
          
            % 1. PRECHOD VNUTORNOU VRSTVOU        
            %_______________Priesecnik_________________________________________________
            P0 = [X1(jj),Y1(jj),Zcalc1(jj)];
            P1 = [X2(jj),Y2(jj),Zcalc2(jj)];
%             P0 = [X1(jj),Y1(jj),Z1(jj)];
%             P1 = [X2(jj),Y2(jj),Z2(jj)]; 
            S = [0,0,0];      % sphere center
            %Vypocet priesecnikov v 3D :
            dx = P1(1)-P0(1); dy = P1(2)-P0(2);  dz = P1(3)-P0(3);
            a = dx^2 + dy^2 + dz^2;
            b = 2*dx*(P0(1)-S(1)) + 2*dy*(P0(2)-S(2)) + 2*dz*(P0(3)-S(3));
            c = S(1)^2 + S(2)^2 + S(3)^2 + P0(1)^2 + P0(2)^2 + P0(3)^2 - 2*(S(1)*P0(1) + S(2)*P0(2) + S(3)*P0(3)) - R2^2;
            D = b^2 - 4*a*c;
            t1 = (-b -sqrt(D))/(2*a);
            t2 = (-b +sqrt(D))/(2*a);
            % PR1:
            Xn = P0(1)+t1*dx;   Yn = P0(2)+t1*dy;   Zn = P0(3)+t1*dz;
            % PR2:
            Xn2 = P0(1)+t2*dx;   Yn2 = P0(2)+t2*dy;   Zn2 = P0(3)+t2*dz;
%             Znp = (Zn-R1)*(-1);
%             Zn2p = (Zn2-R1)*(-1);
            
            %_____________________________________________________________________________
            ElectronFC(i).Xn(jj,1) = ElectronOUT(i).Xn(jj,1);
            ElectronFC(i).Yn(jj,1) = ElectronOUT(i).Yn(jj,1);
            ElectronFC(i).Zn(jj,1) = ElectronOUT(i).Zn(jj,1);

            if IndZ1(jj) > 0
            ElectronFC(i).X(jj,1:IndZ1(jj))     = ElectronOUT(i).X(jj,1:IndZ1(jj));
            ElectronFC(i).Y(jj,1:IndZ1(jj))     = ElectronOUT(i).Y(jj,1:IndZ1(jj));
            ElectronFC(i).Z(jj,1:IndZ1(jj))     = ElectronOUT(i).Z(jj,1:IndZ1(jj));
            ElectronFC(i).Th(jj,1:IndZ1(jj))    = ElectronOUT(i).Th(jj,1:IndZ1(jj));
            ElectronFC(i).Ps(jj,1:IndZ1(jj))    = ElectronOUT(i).Ps(jj,1:IndZ1(jj));
            ElectronFC(i).dE(jj,1:IndZ1(jj))    = ElectronOUT(i).dE(jj,1:IndZ1(jj));
            ElectronFC(i).SE(jj,1:IndZ1(jj))    = ElectronOUT(i).SE(jj,1:IndZ1(jj));
            ElectronFC(i).Zcalc(jj,1:IndZ1(jj)) = ElectronOUT(i).Zcalc(jj,1:IndZ1(jj));
            dEn = ElectronOUT(i).dE(jj,IndZ1(jj));
            TH_nx = Th1(IndZ1(jj));
            else 
            dEn = 0;
            TH_nx = 0;
            end
            %indexovana nula kvoli posunu zaciatku 
            ind0 = find(ElectronIN.Z(jj,:)~=0);  % len v miestach kolizie
            index0 = ind0(end);
            %naklon podla uhlu na priesecniku
            
            TH_ny = 0; 
            RMx = [cos(TH_nx), -sin(TH_nx); sin(TH_nx),cos(TH_nx)];
            Mx = [ElectronIN.X(jj,1:index0);ElectronIN.Z(jj,1:index0)]';
            M_newx = Mx*RMx;
            
            ElectronZ = M_newx(:,2)';  % (jj,:)
            ElectronX = M_newx(:,1)' + Xn;
            
            RMy = [cos(TH_ny), -sin(TH_ny); sin(TH_ny),cos(TH_ny)];
            My = [ElectronIN.Y(jj,1:index0); ElectronZ]';
            M_newy = My*RMy;
            
%             ElectronZcalc = M_newy(:,2)' + Zn;
            ElectronZcalc = Zn - M_newy(:,2)';
            ElectronY = M_newy(:,1)' + Yn;
            ElectronZ = abs(ElectronZcalc-R1);
            ElectronTh = ElectronIN.Th(jj,1:index0) + TH_nx;
            ElectrondE = ElectronIN.dE(jj,1:index0) + dEn;
            ElectronPs = ElectronIN.Ps(jj,1:index0);
            
            %______________________________________________________________
            %hladam kde vychadza z vnutra kapsle
            PrienikyINS = sqrt(ElectronX.^2 + ElectronY.^2 + ElectronZcalc.^2);
%             PrienikyINS = sqrt(ElectronX.^2 + ElectronY.^2 + ElectronZ.^2);
            PrienikyINS(PrienikyINS<R2) = 0;
            PrienikyINS(PrienikyINS>0)= 1;
            [maxim,indINS] = max(PrienikyINS);
            if indINS == 1 && maxim~=0
               P0 = [Xn,Yn,Zn];   % da sa zjednodusit ?? 
               dEn2 = ElectrondE(indINS);
               TH_nx2 = ElectronTh(indINS);
               TH_ny2 = 0;
               Ps2 = ElectronPs(indINS);
%                ElectronX = Xn;
%                ElectronY = Yn;
%                ElectronZ = Znp;
%                ElectronZcalc = Zn;
               P1 = [ElectronX(indINS),ElectronY(indINS),ElectronZcalc(indINS)];
            
            elseif maxim == 0 && ElectronZcalc(end)>ElectronZcalc(end-1)
               P0 = [ElectronX(end),ElectronY(end),ElectronZcalc(end)];
               dEn2 = ElectrondE(end);
               TH_nx2 = ElectronTh(end);
               TH_ny2 = 0;
               Ps2 = ElectronPs(end);
               P1 = [Xn,Yn,Zn];
            elseif indINS > 1 && maxim~=0
               P0 = [ElectronX(indINS-1),ElectronY(indINS-1),ElectronZcalc(indINS-1)];
               dEn2 = ElectrondE(indINS-1);
               TH_nx2 = ElectronTh(indINS-1);
               TH_ny2 = 0;
               Ps2 = ElectronPs(indINS-1);
               P1 = [ElectronX(indINS),ElectronY(indINS),ElectronZcalc(indINS)];
            end
            
            
            dx = P1(1)-P0(1); dy = P1(2)-P0(2);  dz = P1(3)-P0(3);
            a = dx^2 + dy^2 + dz^2;
            b = 2*dx*(P0(1)-S(1)) + 2*dy*(P0(2)-S(2)) + 2*dz*(P0(3)-S(3));
            c = S(1)^2 + S(2)^2 + S(3)^2 + P0(1)^2 + P0(2)^2 + P0(3)^2 - 2*(S(1)*P0(1) + S(2)*P0(2) + S(3)*P0(3)) - R2^2;
            D = b^2 - 4*a*c;
            t1 = (-b -sqrt(D))/(2*a);
            t2 = (-b +sqrt(D))/(2*a);
            % PR1:
            Xn3 = P0(1)+t1*dx;   Yn3 = P0(2)+t1*dy;   Zn3 = P0(3)+t1*dz;
            % PR2:
            Xn4 = P0(1)+t2*dx;   Yn4 = P0(2)+t2*dy;   Zn4 = P0(3)+t2*dz;
%             Zn3p = (Zn3-R1)*(-1);
%             Zn4p = (Zn4-R1)*(-1);
            
            %_______________________________________________________________________
            % pridruzenie vnutra a znovu vonkajska
            %indexovana nula kvoli posunu zaciatku 
            ind1 = find(Electron1.Z(jj,:)~=0);  % len v miestach kolizie
            index1 = ind1(end);
            
            RMx = [cos(TH_nx2), -sin(TH_nx2); sin(TH_nx2),cos(TH_nx2)];
            Mx = [Electron1.X(jj,1:index1);Electron1.Z(jj,1:index1)]';
            M_newx = Mx*RMx;
            
            ElectronZ2 = M_newx(:,2)';  % (jj,:)
            ElectronX2 = M_newx(:,1)' + Xn4;
            
            RMy = [cos(TH_ny2), -sin(TH_ny2); sin(TH_ny2),cos(TH_ny2)];
            My = [Electron1.Y(jj,1:index1); ElectronZ2]';
            M_newy = My*RMy;
            
            ElectronZ2calc = Zn4 - M_newy(:,2)';
            ElectronY2 = M_newy(:,1)' + Yn4;
            ElectronZ2 = abs(ElectronZ2calc-R1);
            ElectronTh2 = Electron1.Th(jj,1:index1) + TH_nx2;
            ElectrondE2 = Electron1.dE(jj,1:index1) + dEn2;
            ElectronPs2 = Electron1.Ps(jj,1:index1) + Ps2;
            
            %Vystup z vonkajsej slupky
            PrienikyINS2 = sqrt(ElectronX2.^2 + ElectronY2.^2 + ElectronZ2calc.^2);

            %             PrienikyINS2(PrienikyINS2>R2) = 0;
            PrienikyINS2(PrienikyINS2<R1) = 0;
            PrienikyINS2(PrienikyINS2>0)= 1;
            [maxim2,indINS2] = max(PrienikyINS2);  
            
            %Zlozenie prechodu dovnutra a zasa von z vnutra
            ElectronADDX = [ElectronX(1:indINS),ElectronX2(indINS2:end)];
            ElectronADDY = [ElectronY(1:indINS),ElectronY2(indINS2:end)];
            ElectronADDZ = [ElectronZ(1:indINS),ElectronZ2(indINS2:end)];
            ElectronADDZcalc = [ElectronZcalc(1:indINS),ElectronZ2calc(indINS2:end)];
            ElectronADDTh = [ElectronTh(1:indINS),ElectronTh2(indINS2:end)];
            ElectronADDdE = [ElectrondE(1:indINS),ElectrondE2(indINS2:end)];
            ElectronADDPs = [ElectronPs(1:indINS),ElectronPs2(indINS2:end)];
%             ElectronADDSE = [ElectronSE(1:indINS1),ElectronSE2(1:indINS2)];
            
            % Zlozenie predchadzajuceho so vstupm do struktury = celkova
            % struktura
            ll = length(ElectronADDX)-1;
            ElectronFC(i).X(jj,IndZ2(jj):IndZ2(jj)+ll)     = ElectronADDX;
            ElectronFC(i).Y(jj,IndZ2(jj):IndZ2(jj)+ll)     = ElectronADDY;
            ElectronFC(i).Z(jj,IndZ2(jj):IndZ2(jj)+ll)     = ElectronADDZ;
            ElectronFC(i).Th(jj,IndZ2(jj):IndZ2(jj)+ll)    = ElectronADDTh;
            ElectronFC(i).Ps(jj,IndZ2(jj):IndZ2(jj)+ll)    = ElectronADDPs;
            ElectronFC(i).dE(jj,IndZ2(jj):IndZ2(jj)+ll)    = ElectronADDdE;
%             ElectronFC(i).SE(jj,inds2(jj))    = ElectronOUT(i).SE(jj,1:inds1(jj));
            ElectronFC(i).Zcalc(jj,IndZ2(jj):IndZ2(jj)+ll) = ElectronADDZcalc;
            ElectronFC(i).IndexDraw(jj,1) = IndZ2(jj)+ll; 
            ElectronFC(i).ISn(jj,1:3) = [Xn,Yn,Zn];
            ElectronFC(i).ISn4(jj,1:3) = [Xn4,Yn4,Zn4];
            
            % hladanie BSE vevnitr struktur (nedostal se ven)
            PrienikyCALCbse = sqrt(ElectronFC(i).X(jj,:).^2 + ElectronFC(i).Y(jj,:).^2 + ElectronFC(i).Zcalc(jj,:).^2);
            PrienikyCALCbse(PrienikyCALCbse==0) = inf;
            PrienikyCALCbse(PrienikyCALCbse>R1) = 0;
            PrienikyCALCbse(PrienikyCALCbse>0)= 1;
            vektorBSE = PrienikyCALCbse.*ElectronFC(i).Zcalc(jj,:);
            [mini IndBSE] = min(vektorBSE(vektorBSE~=0));
            
            
            PrienikyCALC = sqrt(ElectronFC(i).X(jj,:).^2 + ElectronFC(i).Y(jj,:).^2 + ElectronFC(i).Zcalc(jj,:).^2);
            PrienikyCALC(PrienikyCALC<R1) = 0;
            PrienikyCALC(PrienikyCALC>0)= 1;
            INDEX = find(PrienikyCALC==1);
            [maximCALC,indCALC] = max(PrienikyCALC);  
            
            if IndBSE ~= length(vektorBSE(vektorBSE~=0))
               ElectronFC(i).USE(jj,1) = 0;
               ElectronFC(i).SCE(jj,1) = 0;
               ElectronFC(i).BSE(jj,1) = 1;
            elseif indCALC==1 && ElectronFC(i).Z(jj,1)>R1/2   %  <0
               ElectronFC(i).USE(jj,1) = 1;
               ElectronFC(i).SCE(jj,1) = 0;
               ElectronFC(i).BSE(jj,1) = 0;
            elseif indCALC==1 && ElectronFC(i).Z(jj,1)<R1/2   %   >0
               ElectronFC(i).USE(jj,1) = 0;
               ElectronFC(i).SCE(jj,1) = 0;
               ElectronFC(i).BSE(jj,1) = 1;
            elseif indCALC>1 && ElectronFC(i).Z(jj,indCALC)<R1/2   %   >0
               ElectronFC(i).USE(jj,1) = 0;
               ElectronFC(i).SCE(jj,1) = 0;
               ElectronFC(i).BSE(jj,1) = 1;
            elseif indCALC>1 && ElectronFC(i).Z(jj,indCALC) >R1/2   %  <=0
               ElectronFC(i).USE(jj,1) = 0;
               ElectronFC(i).SCE(jj,1) = 1;
               ElectronFC(i).BSE(jj,1) = 0; 
            else 
               ElectronFC(i).USE(jj,1) = 1;
               ElectronFC(i).SCE(jj,1) = 0;
               ElectronFC(i).BSE(jj,1) = 0; 
            end
            
            
            
            if maximCALC == 0  % BSE alebo absorb
                ElectronFC(i).THETA(jj,1) = ElectronOUT(i).Th(jj,INDEX(end));
                ElectronFC(i).IndexDraw(jj,1) = INDEX(end);
            elseif maximCALC == 1 && indCALC == 1 % hned prvy rozptyl je mimo gulu
                ElectronFC(i).THETA(jj,1) = TH_nx;
                ElectronFC(i).THETA(jj,1) = ElectronOUT(i).iTH_X(jj,1);
                ElectronFC(i).IndexDraw(jj,1) = indCALC;
            elseif maximCALC == 1 && indCALC > 1 % nastal rozptyl, elektron vychadza vonku az ponom
                ElectronFC(i).THETA(jj,1) = ElectronOUT(i).Th(jj,indCALC);
                ElectronFC(i).IndexDraw(jj,1) = indCALC;
            else
                disp('nezaradeny rozptyl');
            end
            
            THETA = abs(ElectronFC(i).THETA(jj,1));
            if THETA <= Thd1
                ElectronFC(i).BF(jj,1) = 1;
                ElectronFC(i).DF(jj,1) = 0;
                ElectronFC(i).HAADF(jj,1) = 0;
                ElectronFC(i).BSEf(jj,1) = 0;
            elseif THETA > Thd1 && THETA <= Thd3
                ElectronFC(i).DF(jj,1) = 1;
                ElectronFC(i).BF(jj,1) = 0;
                ElectronFC(i).HAADF(jj,1) = 0;
                ElectronFC(i).BSEf(jj,1) = 0;
            elseif THETA > Thd3 && THETA <= pi/2
                ElectronFC(i).HAADF(jj,1) = 1;
                ElectronFC(i).DF(jj,1) = 0;
                ElectronFC(i).BF(jj,1) = 0;
                ElectronFC(i).BSEf(jj,1) = 0;
            else
                ElectronFC(i).HAADF(jj,1) = 0;
                ElectronFC(i).DF(jj,1) = 0;
                ElectronFC(i).BF(jj,1) = 0;
                ElectronFC(i).BSEf(jj,1) = 1;
            end
    end
    
    BF(i) = sum(ElectronFC(i).BF(:,1))/v1;
    DF(i) = sum(ElectronFC(i).DF(:,1))/v1;
    HAADF(i) = sum(ElectronFC(i).HAADF(:,1))/v1;
    SHIFT(i) = ElectronOUT(i).SHIFT;
        
    ElectronFC(i).FrUSE = sum(ElectronFC(i).USE)/v1;
    ElectronFC(i).FrSCE = sum(ElectronFC(i).SCE)/v1;
    ElectronFC(i).FrBSE = sum(ElectronFC(i).BSE)/v1;
    ElectronFC(i).FrUSE = 1-(ElectronFC(i).FrBSE+ElectronFC(i).FrSCE); 
    ElectronFC(i).SHIFT = ElectronOUT(i).SHIFT;
    
    FrSCE(i) = ElectronFC(i).FrSCE;
    FrBSE(i) = ElectronFC(i).FrBSE;
    FrUSE(i) = ElectronFC(i).FrUSE;
    FrUSE(i) = 1-(ElectronFC(i).FrBSE+ElectronFC(i).FrSCE); 
    SHIFT(i) = ElectronFC(i).SHIFT;
    
    end
close(h)

% dt = string(datetime);
% dt(dt==':') = '_';
% NAME = strcat('Electron_Filled_Capsle_',dt,'.mat');
% save(NAME,'ElectronFC') 
% 
% figure
% plot(SHIFT,FrUSE,'b')
% hold on
% plot(SHIFT,FrBSE,'g')
% plot(SHIFT,FrSCE,'r')
% hold off
% legend('Unscattered','BackScattered','FrontScattered')
% title('Filled Capsle');
% 
figure
    plot(SHIFT,BF,'b')
    hold on
    plot(SHIFT,DF,'g')
    plot(SHIFT,HAADF,'r')
    hold off
    legend('BF','DF','HAADF');
    title('FilledCapsle');
    
    ylim([0,1])
    xlabel('dR [A]'); ylabel('Signal')