clc; clear;
dataTable1 = readtable('10_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable1 = table2array(dataTable1(:,3:end));
dateTable1 = [dataTable1(:,1) dataTable1(:,2)];

dataTable2 = readtable('11_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable2 = table2array(dataTable2(:,3:end));
dateTable2 = [dataTable2(:,1) dataTable2(:,2)];

dataTable3 = readtable('12_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable3 = table2array(dataTable3(:,3:end));
dateTable3 = [dataTable3(:,1) dataTable3(:,2)];

dataTable4 = readtable('13_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable4 = table2array(dataTable4(:,3:end));
dateTable4 = [dataTable4(:,1) dataTable4(:,2)];

dataTable5 = readtable('14_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable5 = table2array(dataTable5(:,3:end));
dateTable5 = [dataTable5(:,1) dataTable5(:,2)];

dataTable6 = readtable('15_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable6 = table2array(dataTable6(:,3:end));
dateTable6 = [dataTable6(:,1) dataTable6(:,2)];

dataTable7 = readtable('16_05_dejvicka.xlsx', 'Sheet', 'List1');
dataTable7 = table2array(dataTable7(:,3:end));
dateTable7 = [dataTable7(:,1) dataTable7(:,2)];

posun = [0 4 7 8 9 13 14 15 17 18 20 22 23 25 28 29 31 33 34 36 39];
PocetDni=7;

Intervaly = readtable('SDDU_PB-PO_1.xlsx', 'Range', 'P1:P673');
Intervaly = table2array(Intervaly);
Intervaly = Intervaly';
%Prideleni zpozdeni do odpovidajicich vektoru
zpozdenOCZlicin2 = [dataTable1(:,4)' dataTable2(:,4)' dataTable3(:,4)' dataTable4(:,4)' dataTable5(:,4)' dataTable6(:,4)' dataTable7(:,4)' ]; 
zpozdenZlicin2 = [dataTable1(:,5)' dataTable2(:,5)' dataTable3(:,5)' dataTable4(:,5)' dataTable5(:,5)' dataTable6(:,5)' dataTable7(:,5)' ]; 
zpozdenSidliste2 = [dataTable1(:,6)' dataTable2(:,6)' dataTable3(:,6)' dataTable4(:,6)' dataTable5(:,6)' dataTable6(:,6)' dataTable7(:,6)' ]; 
zpozdenHalenkovska2 = [dataTable1(:,7)' dataTable2(:,7)' dataTable3(:,7)' dataTable4(:,7)' dataTable5(:,7)' dataTable6(:,7)' dataTable7(:,7)']; 
zpozdenStrojirenska2 = [dataTable1(:,8)' dataTable2(:,8)' dataTable3(:,8)' dataTable4(:,8)' dataTable5(:,8)' dataTable6(:,8)' dataTable7(:,8)' ]; 
zpozdenRepy2 = [dataTable1(:,9)' dataTable2(:,9)' dataTable3(:,9)' dataTable4(:,9)' dataTable5(:,9)' dataTable6(:,9)' dataTable7(:,9)' ]; 
zpozdenBlatiny2 = [dataTable1(:,10)' dataTable2(:,10)' dataTable3(:,10)' dataTable4(:,10)' dataTable5(:,10)' dataTable6(:,10)' dataTable7(:,10)' ]; 
zpozdenSlanska2 = [dataTable1(:,11)' dataTable2(:,11)' dataTable3(:,11)' dataTable4(:,11)' dataTable5(:,11)' dataTable6(:,11)' dataTable7(:,11)' ]; 
zpozdenHlusickova2 = [dataTable1(:,12)' dataTable2(:,12)' dataTable3(:,12)' dataTable4(:,12)' dataTable5(:,12)' dataTable6(:,12)' dataTable7(:,12)' ]; 
zpozdenKrematorium2 = [dataTable1(:,13)' dataTable2(:,13)' dataTable3(:,13)' dataTable4(:,13)' dataTable5(:,13)' dataTable6(:,13)' dataTable7(:,13)' ]; 
zpozdenMotol2 = [dataTable1(:,14)' dataTable2(:,14)' dataTable3(:,14)' dataTable4(:,14)' dataTable5(:,14)' dataTable6(:,14)' dataTable7(:,14)' ]; 
zpozdenNemocnice2 = [dataTable1(:,15)' dataTable2(:,15)' dataTable3(:,15)' dataTable4(:,15)' dataTable5(:,15)' dataTable6(:,15)' dataTable7(:,15)' ]; 
zpozdenSafranecka2 = [dataTable1(:,16)' dataTable2(:,16)' dataTable3(:,16)' dataTable4(:,16)' dataTable5(:,16)' dataTable6(:,16)' dataTable7(:,16)' ]; 
zpozdenVypich2 = [dataTable1(:,17)' dataTable2(:,17)' dataTable3(:,17)' dataTable4(:,17)' dataTable5(:,17)' dataTable6(:,17)' dataTable7(:,17)' ]; 
zpozdenBrevnovska2 = [dataTable1(:,18)' dataTable2(:,18)' dataTable3(:,18)' dataTable4(:,18)' dataTable5(:,18)' dataTable6(:,18)' dataTable7(:,18)' ]; 
zpozdenKajetanka2 = [dataTable1(:,19)' dataTable2(:,19)' dataTable3(:,19)' dataTable4(:,19)' dataTable5(:,19)' dataTable6(:,19)' dataTable7(:,19)' ]; 
zpozdenNaPetynce2 = [dataTable1(:,20)' dataTable2(:,20)' dataTable3(:,20)' dataTable4(:,20)' dataTable5(:,20)' dataTable6(:,20)' dataTable7(:,20)' ]; 
zpozdenVozovna2 = [dataTable1(:,21)' dataTable2(:,21)' dataTable3(:,21)' dataTable4(:,21)' dataTable5(:,21)' dataTable6(:,21)' dataTable7(:,21)' ]; 
zpozdenPrasny2 = [dataTable1(:,22)' dataTable2(:,22)' dataTable3(:,22)' dataTable4(:,22)' dataTable5(:,22)' dataTable6(:,22)' dataTable7(:,22)' ]; 
zpozdenVitezne2 = [dataTable1(:,23)' dataTable2(:,23)' dataTable3(:,23)' dataTable4(:,23)' dataTable5(:,23)' dataTable6(:,23)' dataTable7(:,23)' ]; 
zpozdenDejvicka2 = [dataTable1(:,24)' dataTable2(:,24)' dataTable3(:,24)' dataTable4(:,24)' dataTable5(:,24)' dataTable6(:,24)' dataTable7(:,24)' ]; 
%urceni casu pro jednotlive useky
cas = [dateTable1(:,1)' dateTable2(:,1)' dateTable3(:,1)' dateTable4(:,1)' dateTable5(:,1)' dateTable6(:,1)' dateTable7(:,1)'; dateTable1(:,2)' dateTable2(:,2)' dateTable3(:,2)' dateTable4(:,2)' dateTable5(:,2)' dateTable6(:,2)' dateTable7(:,2)'];
j=1;
for i=2:2:length(cas)*2
    switch cas(i-1)
        case 6
            if (cas(i) > 0.2479) && (cas(i) <= 0.3243) || (cas(i) > 0.8555) && (cas(i) <= 0.8916) || (cas(i) > 0.22013) && (cas(i) <= 0.2215)
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)-1)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)-1)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)-1)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)-1)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)-1)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)-2)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)-2)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)-2)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)-2)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)-3)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)-3)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)-3)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)-3)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)-3)/(24*60);
                if (cas(i) > 0.3138) && (cas(i) < 0.8555)
                    casVitezne2(j) = cas(i)+(posun(20)-3)/(24*60);
                    casDejvicka2(j) = cas(i)+(posun(21)-3)/(24*60);  
                else
                    casVitezne2(j) = cas(i)+(posun(20)-4)/(24*60);
                    casDejvicka2(j) = cas(i)+(posun(21)-5)/(24*60); 
                end
                j=j+1; 
            elseif (cas(i) > 0.3243) && (cas(i) <= 0.4166) || (cas(i) > 0.8347) && (cas(i) <= 0.8659)
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+posun(6)/(24*60);
                casBlatiny2(j) = cas(i)+posun(7)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)-1)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)-1)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)-1)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)-1)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)-1)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)-1)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)-1)/(24*60);
                casBrevnovska2(j) = cas(i)+posun(15)/(24*60);
                casKajetanka2(j) = cas(i)+posun(16)/(24*60);
                casNaPetynce2(j) = cas(i)+posun(17)/(24*60);
                casVozovna2(j) = cas(i)+posun(18)/(24*60);
                casPrasny2(j) = cas(i)+posun(19)/(24*60);
                casVitezne2(j) = cas(i)+(posun(20)-2)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-2)/(24*60);
                j=j+1;
            elseif (cas(i) > 0.4166) && (cas(i) <= 0.8347)
                casOCZlicin2(j) = cas(i)+(posun(1)+2)/(24*60);
                casZlicin2(j) = cas(i)+(posun(2)+2)/(24*60);
                casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
                casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
                casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)+2)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)+2)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)+2)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)+2)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)+2)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)+2)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)+2)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)+2)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)+2)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)+2)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)+2)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)+2)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)+2)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)+2)/(24*60);
                casVitezne2(j) = cas(i)+posun(20)/(24*60);
                casDejvicka2(j) = cas(i)+posun(21)/(24*60);
                j=j+1;
            elseif (cas(i) > 0.8916) 
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
                casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
                casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)+1)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)+1)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)+1)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)+1)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)+1)/(24*60);
                casMotol2(j) = cas(i)+posun(11)/(24*60);
                casNemocnice2(j) = cas(i)+posun(12)/(24*60);
                casSafranecka2(j) = cas(i)+posun(13)/(24*60);
                casVypich2(j) = cas(i)+posun(14)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)-1)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)-1)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)-1)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)-1)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)-1)/(24*60);
                casVitezne2(j) = cas(i)+(posun(20)-2)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-3)/(24*60);
                j=j+1;
            elseif (cas(i) > 0.2097) && (cas(i) <= 0.2201) || (cas(i) > 0.2215) && (cas(i) <= 0.2479)
                casZlicin2(j) = cas(i)+posun(1)/(24*60);
                casSidliste2(j) = cas(i)+3/(24*60);
                casHalenkovska2(j) = cas(i)+4/(24*60);
                casStrojirenska2(j) = cas(i)+5/(24*60);
                casRepy2(j) = cas(i)+ 8/(24*60);
                casBlatiny2(j) = cas(i)+9/(24*60);
                casSlanska2(j) = cas(i)+10/(24*60);
                casHlusickova2(j) = cas(i)+12/(24*60);
                casKrematorium2(j) = cas(i)+13/(24*60);
                casMotol2(j) = cas(i)+14/(24*60);
                casNemocnice2(j) = cas(i)+16/(24*60);
                casSafranecka2(j) = cas(i)+17/(24*60);
                casVypich2(j) = cas(i)+19/(24*60);
                casBrevnovska2(j) = cas(i)+21/(24*60);
                casKajetanka2(j) = cas(i)+22/(24*60);
                casNaPetynce2(j) = cas(i)+24/(24*60);
                casVozovna2(j) = cas(i)+26/(24*60);
                casPrasny2(j) = cas(i)+27/(24*60);
                casVitezne2(j) = cas(i)+28/(24*60);
                casDejvicka2(j) = cas(i)+30/(24*60);
                j=j+1;
            elseif (cas(i) > 0.1819) && (cas(i) <= 0.2097)
                casRepy2(j) = cas(i)+posun(1)/(24*60);
                casBlatiny2(j) = cas(i)+1/(24*60);
                casSlanska2(j) = cas(i)+2/(24*60);
                casHlusickova2(j) = cas(i)+4/(24*60);
                casKrematorium2(j) = cas(i)+5/(24*60);
                casMotol2(j) = cas(i)+6/(24*60);
                casNemocnice2(j) = cas(i)+8/(24*60);
                casSafranecka2(j) = cas(i)+9/(24*60);
                casVypich2(j) = cas(i)+11/(24*60);
                casBrevnovska2(j) = cas(i)+13/(24*60);
                casKajetanka2(j) = cas(i)+14/(24*60);
                casNaPetynce2(j) = cas(i)+16/(24*60);
                casVozovna2(j) = cas(i)+18/(24*60);
                casPrasny2(j) = cas(i)+19/(24*60);
                casVitezne2(j) = cas(i)+20/(24*60);
                casDejvicka2(j) = cas(i)+22/(24*60);
                j=j+1;
            else
                casVypich2(j) = cas(i)+posun(1)/(24*60);
                casBrevnovska2(j) = cas(i)+2/(24*60);
                casKajetanka2(j) = cas(i)+3/(24*60);
                casNaPetynce2(j) = cas(i)+5/(24*60);
                casVozovna2(j) = cas(i)+7/(24*60);
                casPrasny2(j) = cas(i)+8/(24*60);
                casVitezne2(j) = cas(i)+9/(24*60);
                casDejvicka2(j) = cas(i)+11/(24*60);
                j=j+1;  
            end
        case 7
             if (cas(i) < 0.1819)
                casVypich2(j) = cas(i)+(posun(1)/(24*60));
                casBrevnovska2(j) = cas(i)+2/(24*60);
                casKajetanka2(j) = cas(i)+3/(24*60);
                casNaPetynce2(j) = cas(i)+5/(24*60);
                casVozovna2(j) = cas(i)+7/(24*60);
                casPrasny2(j) = cas(i)+8/(24*60);
                casVitezne2(j) = cas(i)+9/(24*60);
                casDejvicka2(j) = cas(i)+11/(24*60);
                j=j+1;  
            elseif (cas(i) > 0.2097) && (cas(i) <= 0.2201) || (cas(i) > 0.2215) && (cas(i) <= 0.2479)
                casZlicin2(j) = cas(i)+(posun(1)/(24*60));
                casSidliste2(j) = cas(i)+3/(24*60);
                casHalenkovska2(j) = cas(i)+4/(24*60);
                casStrojirenska2(j) = cas(i)+5/(24*60);
                casRepy2(j) = cas(i)+8/(24*60);
                casBlatiny2(j) = cas(i)+9/(24*60);
                casSlanska2(j) = cas(i)+10/(24*60);
                casHlusickova2(j) = cas(i)+12/(24*60);
                casKrematorium2(j) = cas(i)+13/(24*60);
                casMotol2(j) = cas(i)+14/(24*60);
                casNemocnice2(j) = cas(i)+16/(24*60);
                casSafranecka2(j) = cas(i)+17/(24*60);
                casVypich2(j) = cas(i)+19/(24*60);
                casBrevnovska2(j) = cas(i)+21/(24*60);
                casKajetanka2(j) = cas(i)+22/(24*60);
                casNaPetynce2(j) = cas(i)+24/(24*60);
                casVozovna2(j) = cas(i)+26/(24*60);
                casPrasny2(j) = cas(i)+27/(24*60);
                casVitezne2(j) = cas(i)+28/(24*60);
                casDejvicka2(j) = cas(i)+30/(24*60);;
                j=j+1;
            elseif (cas(i) > 0.1819) && (cas(i) <= 0.2097)
                casRepy2(j) = cas(i)+(posun(1)/(24*60));
                casBlatiny2(j) = cas(i)+1/(24*60);
                casSlanska2(j) = cas(i)+2/(24*60);
                casHlusickova2(j) = cas(i)+4/(24*60);
                casKrematorium2(j) = cas(i)+5/(24*60);
                casMotol2(j) = cas(i)+6/(24*60);
                casNemocnice2(j) = cas(i)+8/(24*60);
                casSafranecka2(j) = cas(i)+9/(24*60);
                casVypich2(j) = cas(i)+11/(24*60);
                casBrevnovska2(j) = cas(i)+13/(24*60);
                casKajetanka2(j) = cas(i)+14/(24*60);
                casNaPetynce2(j) = cas(i)+16/(24*60);
                casVozovna2(j) = cas(i)+18/(24*60);
                casPrasny2(j) = cas(i)+19/(24*60);
                casVitezne2(j) = cas(i)+20/(24*60);
                casDejvicka2(j) = cas(i)+22/(24*60);
                j=j+1;
             elseif (cas(i) > 0.2479) && (cas(i) <= 0.3173) || (cas(i) > 0.22013) && (cas(i) <= 0.2215)
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)-1)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)-1)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)-1)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)-1)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)-1)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)-2)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)-2)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)-2)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)-2)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)-3)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)-3)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)-3)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)-3)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)-3)/(24*60);
                casVitezne2(j) = cas(i)+(posun(20)-4)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-5)/(24*60); 
                j=j+1;                     
             elseif (cas(i) > 0.3173) && (cas(i) <= 0.4270)
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)-1)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)-1)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)-1)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)-1)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)-1)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)-2)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)-2)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)-2)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)-2)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)-2)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)-2)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)-2)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)-2)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)-2)/(24*60);
                casVitezne2(j) = cas(i)+(posun(20)-2)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-2)/(24*60);
                j=j+1;      
             elseif (cas(i) > 0.4270) && (cas(i) <= 0.8347)
                casOCZlicin2(j) = cas(i)+(posun(1)+2)/(24*60);
                casZlicin2(j) = cas(i)+(posun(2)+2)/(24*60);
                casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
                casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
                casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
                casRepy2(j) = cas(i)+(posun(6)+2)/(24*60);
                casBlatiny2(j) = cas(i)+(posun(7)+2)/(24*60);
                casSlanska2(j) = cas(i)+(posun(8)+2)/(24*60);
                casHlusickova2(j) = cas(i)+(posun(9)+2)/(24*60);
                casKrematorium2(j) = cas(i)+(posun(10)+2)/(24*60);
                casMotol2(j) = cas(i)+(posun(11)+2)/(24*60);
                casNemocnice2(j) = cas(i)+(posun(12)+2)/(24*60);
                casSafranecka2(j) = cas(i)+(posun(13)+2)/(24*60);
                casVypich2(j) = cas(i)+(posun(14)+2)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)+2)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)+2)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)+2)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)+2)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)+2)/(24*60);
                casVitezne2(j) = cas(i)+posun(20)/(24*60);
                casDejvicka2(j) = cas(i)+posun(21)/(24*60);
                j=j+1;
             elseif (cas(i) > 0.8347) && (cas(i) <= 0.8659)
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+posun(6)/(24*60);
                casBlatiny2(j) = cas(i)+posun(7)/(24*60);
                casSlanska2(j) = cas(i)+posun(8)/(24*60);
                casHlusickova2(j) = cas(i)+posun(9)/(24*60);
                casKrematorium2(j) = cas(i)+posun(10)/(24*60);
                casMotol2(j) = cas(i)+posun(11)/(24*60);
                casNemocnice2(j) = cas(i)+posun(12)/(24*60);
                casSafranecka2(j) = cas(i)+posun(13)/(24*60);
                casVypich2(j) = cas(i)+posun(14)/(24*60);
                casBrevnovska2(j) = cas(i)+posun(15)/(24*60);
                casKajetanka2(j) = cas(i)+posun(16)/(24*60);
                casNaPetynce2(j) = cas(i)+posun(17)/(24*60);
                casVozovna2(j) = cas(i)+posun(18)/(24*60);
                casPrasny2(j) = cas(i)+posun(19)/(24*60);
                if (cas(i) > 0.85625) 
                    casVitezne2(j) = cas(i)+(posun(20)-3)/(24*60);
                    casDejvicka2(j) = cas(i)+(posun(21)-4)/(24*60);  
                else
                    casVitezne2(j) = cas(i)+(posun(20)-2)/(24*60);
                    casDejvicka2(j) = cas(i)+(posun(21)-2)/(24*60);
                end
                j=j+1;
             else
                casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
                casZlicin2(j) = cas(i)+posun(2)/(24*60);
                casSidliste2(j) = cas(i)+posun(3)/(24*60);
                casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
                casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
                casRepy2(j) = cas(i)+posun(6)/(24*60);
                casBlatiny2(j) = cas(i)+posun(7)/(24*60);
                casSlanska2(j) = cas(i)+posun(8)/(24*60);
                casHlusickova2(j) = cas(i)+posun(9)/(24*60);
                casKrematorium2(j) = cas(i)+posun(10)/(24*60);
                casMotol2(j) = cas(i)+posun(11)/(24*60);
                casNemocnice2(j) = cas(i)+posun(12)/(24*60);
                casSafranecka2(j) = cas(i)+posun(13)/(24*60);
                casVypich2(j) = cas(i)+posun(14)/(24*60);
                casBrevnovska2(j) = cas(i)+(posun(15)-1)/(24*60);
                casKajetanka2(j) = cas(i)+(posun(16)-1)/(24*60);
                casNaPetynce2(j) = cas(i)+(posun(17)-1)/(24*60);
                casVozovna2(j) = cas(i)+(posun(18)-1)/(24*60);
                casPrasny2(j) = cas(i)+(posun(19)-1)/(24*60);
                casVitezne2(j) = cas(i)+(posun(20)-3)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-5)/(24*60);
                j=j+1;  
             end
        otherwise            
   if (cas(i) < 0.1861) || (cas(i) > 0.2083) && (cas(i) <= 0.2159)
       casVypich2(j) = cas(i)+posun(1)/(24*60);
        casBrevnovska2(j) = cas(i)+3/(24*60);
        casKajetanka2(j) = cas(i)+4/(24*60);
        casNaPetynce2(j) = cas(i)+6/(24*60);
        casVozovna2(j) = cas(i)+8/(24*60);
        casPrasny2(j) = cas(i)+9/(24*60);
        casVitezne2(j) = cas(i)+11/(24*60);
        casDejvicka2(j) = cas(i)+14/(24*60);
        j=j+1; 
   elseif (cas(i) > 0.1861) && (cas(i) <= 0.2013) || (cas(i) > 0.2083) && (cas(i) <= 0.22083) || (cas(i) > 0.2339) && (cas(i) <= 0.2341) || (cas(i) > 0.2443) && (cas(i) <= 0.2445) || (cas(i) > 0.2527) && (cas(i) <= 0.2529)
       casRepy2(j) = cas(i)+posun(1)/(24*60);
       casBlatiny2(j) = cas(i)+1/(24*60);
       casSlanska2(j) = cas(i)+2/(24*60);
       casHlusickova2(j) = cas(i)+4/(24*60);
       casKrematorium2(j) = cas(i)+5/(24*60);
       casMotol2(j) = cas(i)+6/(24*60);
       casNemocnice2(j) = cas(i)+8/(24*60);
       casSafranecka2(j) = cas(i)+9/(24*60);
       casVypich2(j) = cas(i)+11/(24*60);
       casBrevnovska2(j) = cas(i)+14/(24*60);
       casKajetanka2(j) = cas(i)+15/(24*60);
       casNaPetynce2(j) = cas(i)+17/(24*60);
       casVozovna2(j) = cas(i)+19/(24*60);
       casPrasny2(j) = cas(i)+20/(24*60);
       casVitezne2(j) = cas(i)+22/(24*60);
       casDejvicka2(j) = cas(i)+25/(24*60);
       j=j+1;
   elseif (cas(i) > 0.2075) && (cas(i) <= 0.2077) || (cas(i) > 0.2214) && (cas(i) <= 0.2216) || (cas(i) > 0.2506) && (cas(i) <= 0.2508) || (cas(i) > 0.2589) && (cas(i) <= 0.2591) || (cas(i) > 0.2673) && (cas(i) <= 0.2675) ||(cas(i) > 0.2756) && (cas(i) <= 0.2758) || (cas(i) > 0.2846) && (cas(i) <= 0.2848) || (cas(i) > 0.2930) && (cas(i) <= 0.2932) || (cas(i) > 0.3013) && (cas(i) <= 0.3015) || (cas(i) > 0.3096) && (cas(i) <= 0.3098) || (cas(i) > 0.3180) && (cas(i) <= 0.3182) || (cas(i) > 0.3263) && (cas(i) <= 0.3265) || (cas(i) > 0.3346) && (cas(i) <= 0.3348) || (cas(i) > 0.3430) && (cas(i) <= 0.3432) ||(cas(i) > 0.3520) && (cas(i) <= 0.3522) ||(cas(i) > 0.3631) && (cas(i) <= 0.3633) 
       casZlicin2(j) = cas(i)+posun(1)/(24*60);
       casSidliste2(j) = cas(i)+(posun(3)-4)/(24*60);
       casHalenkovska2(j) = cas(i)+(posun(4)-4)/(24*60);
       casStrojirenska2(j) = cas(i)+(posun(5)-4)/(24*60);
       casRepy2(j) = cas(i)+(posun(6)-4)/(24*60);
       casBlatiny2(j) = cas(i)+(posun(7)-4)/(24*60);
       casSlanska2(j) = cas(i)+(posun(8)-4)/(24*60);
       casHlusickova2(j) = cas(i)+(posun(9)-4)/(24*60);
       casKrematorium2(j) = cas(i)+(posun(10)-4)/(24*60);
       casMotol2(j) = cas(i)+(posun(11)-4)/(24*60);
       casNemocnice2(j) = cas(i)+(posun(12)-4)/(24*60);
       casSafranecka2(j) = cas(i)+(posun(13)-4)/(24*60);
       casVypich2(j) = cas(i)+(posun(14)-4)/(24*60);
       casBrevnovska2(j) = cas(i)+(posun(15)-4)/(24*60);
       casKajetanka2(j) = cas(i)+(posun(16)-4)/(24*60);
       casNaPetynce2(j) = cas(i)+(posun(17)-4)/(24*60);
       casVozovna2(j) = cas(i)+(posun(18)-4)/(24*60);
       casPrasny2(j) = cas(i)+(posun(19)-4)/(24*60);
       casVitezne2(j) = cas(i)+(posun(20)-4)/(24*60);
       casDejvicka2(j) = cas(i)+(posun(21)-4)/(24*60);
       j=j+1;
   elseif (cas(i) > 0.22986) && (cas(i) <= 0.5875) 
       casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
       casZlicin2(j) = cas(i)+posun(2)/(24*60);
       casSidliste2(j) = cas(i)+posun(3)/(24*60);
       casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
       casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
       casRepy2(j) = cas(i)+posun(6)/(24*60);
       casBlatiny2(j) = cas(i)+posun(7)/(24*60);
       casSlanska2(j) = cas(i)+posun(8)/(24*60);
       casHlusickova2(j) = cas(i)+posun(9)/(24*60);
       casKrematorium2(j) = cas(i)+posun(10)/(24*60);
       casMotol2(j) = cas(i)+posun(11)/(24*60);
       casNemocnice2(j) = cas(i)+posun(12)/(24*60);
       casSafranecka2(j) = cas(i)+posun(13)/(24*60);
       casVypich2(j) = cas(i)+posun(14)/(24*60);
       casBrevnovska2(j) = cas(i)+posun(15)/(24*60);
       casKajetanka2(j) = cas(i)+posun(16)/(24*60);
       casNaPetynce2(j) = cas(i)+posun(17)/(24*60);
       casVozovna2(j) = cas(i)+posun(18)/(24*60);
       casPrasny2(j) = cas(i)+posun(19)/(24*60);
       casVitezne2(j) = cas(i)+posun(20)/(24*60);
       casDejvicka2(j) = cas(i)+posun(21)/(24*60);
       j=j+1;      
   elseif (cas(i) > 0.5875) && (cas(i) <= 0.7590)
        casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
        casZlicin2(j) = cas(i)+(posun(2)+2)/(24*60);
        casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
        casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
        casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
        casRepy2(j) = cas(i)+(posun(6)+2)/(24*60);
        casBlatiny2(j) = cas(i)+(posun(7)+2)/(24*60);
        casSlanska2(j) = cas(i)+(posun(8)+2)/(24*60);
        casHlusickova2(j) = cas(i)+(posun(9)+2)/(24*60);
        casKrematorium2(j) = cas(i)+(posun(10)+2)/(24*60);
        casMotol2(j) = cas(i)+(posun(11)+2)/(24*60);
        casNemocnice2(j) = cas(i)+(posun(12)+2)/(24*60);
        casSafranecka2(j) = cas(i)+(posun(13)+2)/(24*60);
        casVypich2(j) = cas(i)+(posun(14)+2)/(24*60);
        casBrevnovska2(j) = cas(i)+(posun(15)+2)/(24*60);
        casKajetanka2(j) = cas(i)+(posun(16)+2)/(24*60);
        casNaPetynce2(j) = cas(i)+(posun(17)+2)/(24*60);
        casVozovna2(j) = cas(i)+(posun(18)+2)/(24*60);
        casPrasny2(j) = cas(i)+(posun(19)+2)/(24*60);
        casVitezne2(j) = cas(i)+(posun(20)+2)/(24*60);
        casDejvicka2(j) = cas(i)+(posun(21)+2)/(24*60);
        j=j+1;
   elseif (cas(i) > 0.7590) && (cas(i) <= 0.7604)
        casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
        casZlicin2(j) = cas(i)+(posun(2)+2)/(24*60);
        casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
        casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
        casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
        casRepy2(j) = cas(i)+(posun(6)+2)/(24*60);
        casBlatiny2(j) = cas(i)+(posun(7)+2)/(24*60);
        casSlanska2(j) = cas(i)+(posun(8)+2)/(24*60);
        casHlusickova2(j) = cas(i)+(posun(9)+2)/(24*60);
        casKrematorium2(j) = cas(i)+(posun(10)+2)/(24*60);
        casMotol2(j) = cas(i)+(posun(11)+1)/(24*60);
        casNemocnice2(j) = cas(i)+(posun(12)+1)/(24*60);
        casSafranecka2(j) = cas(i)+(posun(13)+1)/(24*60);
        casVypich2(j) = cas(i)+(posun(14)+1)/(24*60);
        casBrevnovska2(j) = cas(i)+(posun(15)+1)/(24*60);
        casKajetanka2(j) = cas(i)+(posun(16)+1)/(24*60);
        casNaPetynce2(j) = cas(i)+(posun(17)+1)/(24*60);
        casVozovna2(j) = cas(i)+(posun(18)+1)/(24*60);
        casPrasny2(j) = cas(i)+(posun(19)+1)/(24*60);
        casVitezne2(j) = cas(i)+(posun(20)+1)/(24*60);
        casDejvicka2(j) = cas(i)+(posun(21)+1)/(24*60);
        j=j+1;
      elseif (cas(i) > 0.7590) && (cas(i) <= 0.8347)
        casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
        casZlicin2(j) = cas(i)+(posun(2)+2)/(24*60);
        casSidliste2(j) = cas(i)+(posun(3)+2)/(24*60);
        casHalenkovska2(j) = cas(i)+(posun(4)+2)/(24*60);
        casStrojirenska2(j) = cas(i)+(posun(5)+2)/(24*60);
        casRepy2(j) = cas(i)+(posun(6)+1)/(24*60);
        casBlatiny2(j) = cas(i)+(posun(7)+1)/(24*60);
        casSlanska2(j) = cas(i)+(posun(8)+1)/(24*60);
        casHlusickova2(j) = cas(i)+(posun(9)+1)/(24*60);
        casKrematorium2(j) = cas(i)+(posun(10)+1)/(24*60);
        casMotol2(j) = cas(i)+(posun(11))/(24*60);
        casNemocnice2(j) = cas(i)+(posun(12))/(24*60);
        casSafranecka2(j) = cas(i)+(posun(13))/(24*60);
        casVypich2(j) = cas(i)+(posun(14))/(24*60);
        casBrevnovska2(j) = cas(i)+(posun(15))/(24*60);
        casKajetanka2(j) = cas(i)+(posun(16))/(24*60);
        casNaPetynce2(j) = cas(i)+(posun(17))/(24*60);
        casVozovna2(j) = cas(i)+(posun(18))/(24*60);
        casPrasny2(j) = cas(i)+(posun(19))/(24*60);
        casVitezne2(j) = cas(i)+(posun(20))/(24*60);
        casDejvicka2(j) = cas(i)+(posun(21))/(24*60);
        j=j+1;
   else
       casOCZlicin2(j) = cas(i)+posun(1)/(24*60);
       casZlicin2(j) = cas(i)+posun(2)/(24*60);
       casSidliste2(j) = cas(i)+posun(3)/(24*60);
       casHalenkovska2(j) = cas(i)+posun(4)/(24*60);
       casStrojirenska2(j) = cas(i)+posun(5)/(24*60);
       casRepy2(j) = cas(i)+(posun(6)-1)/(24*60);
       casBlatiny2(j) = cas(i)+(posun(7)-1)/(24*60);
       casSlanska2(j) = cas(i)+(posun(8)-1)/(24*60);
       casHlusickova2(j) = cas(i)+(posun(9)-1)/(24*60);
       casKrematorium2(j) = cas(i)+(posun(10)-1)/(24*60);
        casMotol2(j) = cas(i)+(posun(11)-2)/(24*60);
        casNemocnice2(j) = cas(i)+(posun(12)-2)/(24*60);
        casSafranecka2(j) = cas(i)+(posun(13)-2)/(24*60);
        casVypich2(j) = cas(i)+(posun(14)-2)/(24*60);
        if cas(i) > (0.86597)
            casBrevnovska2(j) = cas(i)+(posun(15)-2)/(24*60);
            casKajetanka2(j) = cas(i)+(posun(16)-2)/(24*60);
            casNaPetynce2(j) = cas(i)+(posun(17)-2)/(24*60);
            casVozovna2(j) = cas(i)+(posun(18)-2)/(24*60);
            casPrasny2(j) = cas(i)+(posun(19)-2)/(24*60);
            if (cas(i) < 0.7590)
                casVitezne2(j) = cas(i)+(posun(20)-2)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-2)/(24*60);
            else
                casVitezne2(j) = cas(i)+(posun(20)-3)/(24*60);
                casDejvicka2(j) = cas(i)+(posun(21)-4)/(24*60); 
            end
        else
            casBrevnovska2(j) = cas(i)+(posun(15)-3)/(24*60);
            casKajetanka2(j) = cas(i)+(posun(16)-3)/(24*60);
            casNaPetynce2(j) = cas(i)+(posun(17)-3)/(24*60);
            casVozovna2(j) = cas(i)+(posun(18)-3)/(24*60);
            casPrasny2(j) = cas(i)+(posun(19)-3)/(24*60);
            casVitezne2(j) = cas(i)+(posun(20)-4)/(24*60);
            casDejvicka2(j) = cas(i)+(posun(21)-5)/(24*60);
        end
        j=j+1;
   end
    end
    
end
cas = cas(1,:);
%zpracovani dat o pocasi
pocasi1 = readtable('1406pocasi.xlsx', 'Sheet', 'List1', 'Range', 'A1:G48');
pocasi1 = pocasi1(:,[1 3 7]);
pocasi1 = table2array(pocasi1);
pocasi2 = readtable('1406pocasi.xlsx', 'Sheet', 'List2', 'Range', 'A1:G48');
pocasi2 = pocasi2(:,[1 3 7]);
pocasi2 = table2array(pocasi2);
pocasi3 = readtable('1406pocasi.xlsx', 'Sheet', 'List3', 'Range', 'A1:G48');
pocasi3 = pocasi3(:,[1 3 7]);
pocasi3 = table2array(pocasi3);
pocasi4 = readtable('1406pocasi.xlsx', 'Sheet', 'List4', 'Range', 'A1:G48');
pocasi4 = pocasi4(:,[1 3 7]);
pocasi4 = table2array(pocasi4);
pocasi5 = readtable('1406pocasi.xlsx', 'Sheet', 'List5', 'Range', 'A1:G48');
pocasi5 = pocasi5(:,[1 3 7]);
pocasi5 = table2array(pocasi5);
pocasi6 = readtable('1406pocasi.xlsx', 'Sheet', 'List6', 'Range', 'A1:G48');
pocasi6 = pocasi6(:,[1 3 7]);
pocasi6 = table2array(pocasi6);
pocasi7 = readtable('1406pocasi.xlsx', 'Sheet', 'List7', 'Range', 'A1:G48');
pocasi7 = pocasi7(:,[1 3 7]);
pocasi7 = table2array(pocasi7);
pocasi = [[pocasi1(:,1)' pocasi2(:,1)' pocasi3(:,1)' pocasi4(:,1)' pocasi5(:,1)' pocasi6(:,1)' pocasi7(:,1)'];[pocasi1(:,2)' pocasi2(:,2)' pocasi3(:,2)' pocasi4(:,2)' pocasi5(:,2)' pocasi6(:,2)' pocasi7(:,2)']];
prehanky = [pocasi1(:,3)' pocasi2(:,3)' pocasi3(:,3)' pocasi4(:,3)' pocasi5(:,3)' pocasi6(:,3)' pocasi7(:,3)'];
for j = 1:length(Intervaly)
    for L = 1:2:length(pocasi)*2-1
        switch j
            case 97
                for k = 1:(length(pocasi1))*2-1
                    pocasi(k) = -3;
                end
            case 96*2+1
                for k = k:(length(pocasi1))*2+(length(pocasi2))*2-1
                    pocasi(k) = -2;
                end
            case 96*3+1
                for k = k:(length(pocasi1))*2+(length(pocasi2))*2+(length(pocasi3))*2-1
                    pocasi(k) = -1;
                end
            case 96*4+1
                for k = k:(length(pocasi1))*2+(length(pocasi2))*2+(length(pocasi3))*2+(length(pocasi4))*2-1
                    pocasi(k) = 0;
                end  
           case 96*5+1
                for k = k:(length(pocasi1))*2+(length(pocasi2))*2+(length(pocasi3))*2+(length(pocasi4))*2+(length(pocasi5))*2-1
                    pocasi(k) = 0;
                end
           case 96*6+1
                for k = k:(length(pocasi1))*2+(length(pocasi2))*2+(length(pocasi3))*2+(length(pocasi4))*2+(length(pocasi5))*2+(length(pocasi6))*2-1
                    pocasi(k) = 0;
                end
        end
        if mod(j, 96) == 0 
            teplota{1}(j) = pocasi(2*47*fix(j/96));
            teplota{2}(j) = prehanky(47*fix(j/96));
            break
        end
        if Intervaly(j) < pocasi(L)
            if j == 1
                teplota{1}(j) = pocasi(L+1);
                teplota{2}(j) = prehanky((L+1)/2);
                break
            end
            if (L-1) == 0 
                teplota{1}(j) = teplota{1}(j-1);
                teplota{2}(j) = teplota{2}(j-1);
                break
            end
             teplota{1}(j) = pocasi(L-1);
             teplota{2}(j) = prehanky((L-1)/2);
             break
        end
    end
end
teplota{1}(j) = pocasi(length(pocasi)*2);
%zpracovani dat o zpozdeni
Janus = 0;
PrubezneZpozdeni = 0;
for i = 1:length(posun)
    switch i
        case 1
            zpozden = zpozdenOCZlicin2;
            cas2 = casOCZlicin2;
        case 2
            zpozden = zpozdenZlicin2;
            cas2 = casZlicin2;
        case 3
            zpozden = zpozdenSidliste2;
            cas2 = casSidliste2;
        case 4
            zpozden = zpozdenHalenkovska2;
            cas2 = casHalenkovska2;
        case 5
            zpozden = zpozdenStrojirenska2;
            cas2 = casStrojirenska2;
        case 6
            zpozden = zpozdenRepy2;
            cas2 = casRepy2;
       case 7
            zpozden = zpozdenBlatiny2;
            cas2 = casBlatiny2;
       case 8
            zpozden = zpozdenSlanska2;
            cas2 = casSlanska2;
       case 9
            zpozden = zpozdenHlusickova2;
            cas2 = casHlusickova2;
       case 10
            zpozden = zpozdenKrematorium2;
            cas2 = casKrematorium2;
       case 11
            zpozden = zpozdenMotol2;
            cas2 = casMotol2;
       case 12
            zpozden = zpozdenNemocnice2;
            cas2 = casNemocnice2;
       case 13
            zpozden = zpozdenSafranecka2;
            cas2 = casSafranecka2;
       case 14
            zpozden = zpozdenVypich2;
            cas2 = casVypich2;
       case 15
            zpozden = zpozdenBrevnovska2;
            cas2 = casBrevnovska2;
       case 16
            zpozden = zpozdenKajetanka2;
            cas2 = casKajetanka2;
       case 17
            zpozden = zpozdenNaPetynce2;
            cas2 = casNaPetynce2;
       case 18
            zpozden = zpozdenVozovna2;
            cas2 = casVozovna2;
       case 19
            zpozden = zpozdenPrasny2;
            cas2 = casPrasny2;
       case 20
            zpozden = zpozdenVitezne2;
            cas2 = casVitezne2;
       case 21
            zpozden = zpozdenDejvicka2;
            cas2 = casDejvicka2;              
    end
    for Z = 1:length(Intervaly)-1
        switch Z
            case 96
                for ch = 1:length(dataTable1)
                    cas2(ch)=-1;
                end
            case 96*2
                for ch = ch:(length(dataTable1)+length(dataTable2))
                cas2(ch)=-2;  
                end
            case 96*3
                for ch = ch:(length(dataTable1)+length(dataTable2)+length(dataTable3))
                cas2(ch)=-3;  
                end
            case 96*4
                for ch = ch:(length(dataTable1)+length(dataTable2)+length(dataTable3)+length(dataTable4))
                    cas2(ch)=-4;  
                end
            case 96*5
                for ch = ch:(length(dataTable1)+length(dataTable2)+length(dataTable3)+length(dataTable4)+length(dataTable5))
                 cas2(ch)=-5;  
                end  
            case 96*6
                for ch = ch:(length(dataTable1)+length(dataTable2)+length(dataTable3)+length(dataTable4)+length(dataTable5)+length(dataTable6))
                    cas2(ch)=-6;  
                end  
         end
    for ZZ = 1:length(cas2)
        if cas(ZZ) > fix(Z/96)+1
            if Janus == 1
                Janus = 0;
                Zpozdeni{i}(Z) = PrubezneZpozdeni/Pocet{i}(Z);
                PrubezneZpozdeni=0;
                break;
            else
            Zpozdeni{i}(Z) = 0;
            Pocet{i}(Z)=0;
            break;
            end
        end
        if cas(ZZ) == 7 && ZZ == length(cas2)
           if Janus == 1
                Janus = 0;
                Zpozdeni{i}(Z) = PrubezneZpozdeni/Pocet{i}(Z);
                PrubezneZpozdeni=0;
                break;
           else
            Zpozdeni{i}(Z) = 0;
            Pocet{i}(Z)=0;
            break;
            end
        end
        if (Intervaly(Z)<=cas2(ZZ)) && (cas2(ZZ)<Intervaly(Z+1)) %(cas2(ZZ)<Intervaly(Z+1))
            if isnan(zpozden(ZZ)) == 1
                cas2(ZZ)=50;           
            elseif Janus == 1
                Pocet{i}(Z)=Pocet{i}(Z)+1;
                PrubezneZpozdeni=PrubezneZpozdeni+zpozden(ZZ);
                cas2(ZZ)=50;
            else 
                PrubezneZpozdeni = zpozden(ZZ);
                Pocet{i}(Z)=1;
                cas2(ZZ)=50;
                Janus=1;
            end
        end
    end
    end
    Zpozdeni{i}(Z+1)=zpozden(length(zpozden));
    Pocet{i}(Z+1)=0;
end
%spojeni intervalu s odpovidajicimi hodnotami zpozdeni a poctu spoju
OCZlicin2 = [Intervaly; Zpozdeni{1}; Pocet{1}]'; 
Zlicin2 = [Intervaly; Zpozdeni{2}; Pocet{2}]';
Sidliste2 = [Intervaly; Zpozdeni{3}; Pocet{3}]';
Halenkovska2 = [Intervaly; Zpozdeni{4}; Pocet{4}]';
Strojirenska2 = [Intervaly; Zpozdeni{5}; Pocet{5}]';
Repy2 = [Intervaly; Zpozdeni{6}; Pocet{6}]';
Blatiny2 = [Intervaly; Zpozdeni{7}; Pocet{7}]';
Slanska2 = [Intervaly; Zpozdeni{8}; Pocet{8}]';
Hlusickova2 = [Intervaly; Zpozdeni{9}; Pocet{9}]';
Krematorium2 = [Intervaly; Zpozdeni{10}; Pocet{10}]';
Motol2 = [Intervaly; Zpozdeni{11}; Pocet{11}]';
Nemocnice2 = [Intervaly; Zpozdeni{12}; Pocet{12}]';
Safranecka2 = [Intervaly; Zpozdeni{13}; Pocet{13}]';
Vypich2 = [Intervaly; Zpozdeni{14}; Pocet{14}]';
Brevnovska2 = [Intervaly; Zpozdeni{15}; Pocet{15}]';
Kajetanka2 = [Intervaly; Zpozdeni{16}; Pocet{16}]';
NaPetynce2 = [Intervaly; Zpozdeni{17}; Pocet{17}]';
Vozovna2 = [Intervaly; Zpozdeni{18}; Pocet{18}]';
Prasny2 = [Intervaly; Zpozdeni{19}; Pocet{19}]';
Vitezne2 = [Intervaly; Zpozdeni{20}; Pocet{20}]';
Dejvicka2 = [Intervaly; Zpozdeni{21}; Pocet{21}]';
for dd = 1:672
    dZlicin2(dd) = Zlicin2(672+dd) - OCZlicin2(672+dd);
    dSidliste2(dd) = Sidliste2(672+dd) - Zlicin2(672+dd);
    dHalenkovska2(dd) = Halenkovska2(672+dd) - Sidliste2(672+dd);
    dStrojirenska2(dd) = Strojirenska2(672+dd) - Halenkovska2(672+dd);
    dRepy2(dd) = Repy2(672+dd) - Strojirenska2(672+dd);
    dBlatiny2(dd) = Blatiny2(672+dd) - Repy2(672+dd);
    dSlanska2(dd) = Slanska2(672+dd) - Blatiny2(672+dd);
    dHlusickova2(dd) = Hlusickova2(672+dd) - Slanska2(672+dd);
    dKrematorium2(dd) = Krematorium2(672+dd) - Hlusickova2(672+dd);
    dMotol2(dd) = Motol2(672+dd) - Krematorium2(672+dd);
    dNemocnice2(dd) = Nemocnice2(672+dd) - Motol2(672+dd);
    dSafranecka2(dd) = Safranecka2(672+dd) - Nemocnice2(672+dd);
    dVypich2(dd) = Vypich2(672+dd) - Safranecka2(672+dd);
    dBrevnovska2(dd) = Brevnovska2(672+dd) - Vypich2(672+dd);
    dKajetanka2(dd) = Kajetanka2(672+dd) - Brevnovska2(672+dd);
    dNaPetynce2(dd) = NaPetynce2(672+dd) - Kajetanka2(672+dd);
    dVozovna2(dd) = Vozovna2(672+dd) - NaPetynce2(672+dd);
    dPrasny2(dd) = Prasny2(672+dd) - Vozovna2(672+dd);
    dVitezne2(dd) = Vitezne2(672+dd) - Prasny2(672+dd);
    dDejvicka2(dd) = Dejvicka2(672+dd) - Vitezne2(672+dd);
end
%zapis dat do souboru
writematrix(OCZlicin2,'dOCZlicin2.xls', 'Sheet', '0510');
writematrix(Zlicin2,'dZlicin2.xls', 'Sheet', '0510');
writematrix(Sidliste2,'dSidliste2.xls', 'Sheet', '0510');
writematrix(Halenkovska2,'dHalenkovska2.xls', 'Sheet', '0510');
writematrix(Strojirenska2,'dStrojirenska2.xls', 'Sheet', '0510');
writematrix(Repy2,'dRepy2.xls', 'Sheet', '0510');
writematrix(Blatiny2,'dBlatiny2.xls', 'Sheet', '0510');
writematrix(Slanska2,'dSlanska2.xls', 'Sheet', '0510');
writematrix(Hlusickova2,'dHlusickova2.xls', 'Sheet', '0510');
writematrix(Krematorium2,'dKrematorium2.xls', 'Sheet', '0510');
writematrix(Motol2,'dMotol2.xls', 'Sheet', '0510');
writematrix(Nemocnice2,'dNemocnice2.xls', 'Sheet', '0510');
writematrix(Safranecka2,'dSafranecka2.xls', 'Sheet', '0510');
writematrix(Vypich2,'dVypich2.xls', 'Sheet', '0510');
writematrix(Brevnovska2,'dBrevnovska2.xls', 'Sheet', '0510');
writematrix(Kajetanka2,'dKajetanka2.xls', 'Sheet', '0510');
writematrix(NaPetynce2,'dNaPetynce2.xls', 'Sheet', '0510');
writematrix(Vozovna2,'dVozovna2.xls', 'Sheet', '0510');
writematrix(Prasny2,'dPrasny2.xls', 'Sheet', '0510');
writematrix(Vitezne2,'dVitezne2.xls', 'Sheet', '0510');
writematrix(Dejvicka2,'dDejvicka2.xls', 'Sheet', '0510');
