AllStateTrajectory500(:,3)=AllStateTrajectory500(:,3)-1;
AllStateTrajectory500(:,2)=AllStateTrajectory500(:,2)+1;
hmm500=HMMVAR(AllStateTrajectory500(:,1),6,1,[])
AllStateTrajectory200(:,1)=CSingleStates(1,1).eff100;
AllStateTrajectory200(:,2)=ones(length(CSingleStates(1,1).eff100),1);
for i=2:length(CSingleStates)
laenge=length(CSingleStates(1,i).eff100);
state=i*ones(laenge,1);
AllStateTrajectory100(end+1:end+laenge,1:2)=[CSingleStates(1,i).eff100(:,1),state(:,1)];
clear state laenge
end


AllStateTrajectory100(:,1)=CSingleStates(1,1).eff100;
AllStateTrajectory100(:,2)=ones(length(CSingleStates(1,1).eff100),1);
for i=2:length(CSingleStates)
laenge=length(CSingleStates(1,i).eff100);
state=i*ones(laenge,1);
AllStateTrajectory100(end+1:end+laenge,1:2)=[CSingleStates(1,i).eff100(:,1),state(:,1)];
clear state laenge
end



AllStateTrajectory500(:,1)=CSingleStates(1,1).eff500;
AllStateTrajectory500(:,2)=ones(length(CSingleStates(1,1).eff500),1);
for i=2:length(CSingleStates)
laenge=length(CSingleStates(1,i).eff500);
state=i*ones(laenge,1);
AllStateTrajectory500(end+1:end+laenge,1:2)=[CSingleStates(1,i).eff500(:,1),state(:,1)];
clear state laenge
end


VarMean(:,1:2)=VarMean(:,1:2)
VarMean(:,1:2)=VarMean10(:,1:2)
VarMean(:,3:4)=VarMean15(:,1:2)
VarMean(:,5:6)=VarMean20(:,1:2)
for i=1:95
    VarMean25(i,1)=VarMean.NPmean5_25(1,i);
    VarMean25(i,2)=VarMean.NPvar5_25(1,i);
end
VarMean(:,7:8)=VarMean25(:,1:2)
VarMean(:,9:10)=VarMean30(:,1:2)

for i=1:length

for i=1:length(means2)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:FoundStates
AllStateTrajectory500(AllStateTrajectory500(:,2)==FoundStates(k),3)=i;
end
end
for i=1:length(means1)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:FoundStates
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),3)=i*ones;
end
end
find(OutStates(:,1)==2)
for i=1:length(means1)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),3)=i*ones;
end
clear FoundStates
end
for i=1:95
OutStates(i,1)=find(means2>VarMean25(i,1),1)-1;
end
means2=[0 0.3 0.45 0.55 0.65 0.7 1];
for i=1:260
OutStates(i,2)=find(means2>VarMean(i,2),1)-1;
end


for i=1:length(means2)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:length(FoundStates)
AllStateTrajectory500(AllStateTrajectory500(:,2)==FoundStates(k),3)=i*ones;
end
clear FoundStates
end
for i=1:length(means2)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),4)=i*ones;
end

clear FoundStates
end
for i=1:260
OutStates(i,2)=find(means1>VarMean(i,2),1)-1;
end
for i=1:length(means1)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),3)=i*ones;
end
clear FoundStates
end
for i=1:260
OutStates(i,2)=find(means2>VarMean(i,2),1)-1;
end
for i=1:length(means2)-1
FoundStates=find(OutStates(:,1)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),4)=i*ones;
end
clear FoundStates
end
find(OutStates==4)
find(OutStates==4,2)
for i=1:length(means2)-1
FoundStates=find(OutStates(:,2)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),4)=i*ones;
end
clear FoundStates
end
means3=[0 0.25 0.35 0.4 0.45 0.5 0.55 0.6 0.65 0.7 0.8 1 ];
for i=1:260
OutStates(i,3)=find(means3>VarMean(i,2),1)-1;
end
for i=1:length(means3)-1
FoundStates=find(OutStates(:,3)==i);
for k=1:length(FoundStates)
AllStateTrajectory(AllStateTrajectory(:,2)==FoundStates(k),5)=i*ones;
end
clear FoundStates
end





for 
for i=1:length(CSingleStates)
 %laengen(i,1)=length(CSingleStates(1,i).counts);   
CSingleStates(1,i).eff200=effer(timewindow(CSingleStates(1,i).counts,200));
end

for i=1:length(CSingleStates)
CSingleStates(1,i).int10=timewindow(CSingleStates(1,i).counts,10);
CSingleStates(1,i).int20=timewindow(CSingleStates(1,i).counts,20);
CSingleStates(1,i).int50=timewindow(CSingleStates(1,i).counts,50);
CSingleStates(1,i).int100=timewindow(CSingleStates(1,i).counts,100);
end

for i=1:length(CSingleStates)
CSingleStates(1,i).eff10=efficiency(CSingleStates(1,i).int10);
CSingleStates(1,i).eff20=efficiency(CSingleStates(1,i).int20);
CSingleStates(1,i).eff50=efficiency(CSingleStates(1,i).int50);
CSingleStates(1,i).eff100=efficiency(CSingleStates(1,i).int100);
end

for i=1:length(CSingleStates)
   laengen(i,:)=length(CSingleStates(1,i).counts); 
end
figure;

%% Night job

for i=1:length(CSingleStates)

CSingleStates(1,i).NP3_4=NPanalyse(CSingleStates(1,i).monocounts, 3,4);
CSingleStates(1,i).NP3_8=NPanalyse(CSingleStates(1,i).monocounts, 3,8);
CSingleStates(1,i).NP3_10=NPanalyse(CSingleStates(1,i).monocounts, 3,10);
CSingleStates(1,i).NP3_15=NPanalyse(CSingleStates(1,i).monocounts, 3,15);
CSingleStates(1,i).NP3_20=NPanalyse(CSingleStates(1,i).monocounts, 3,20);

CSingleStates(1,i).NP5_5=NPanalyse(CSingleStates(1,i).monocounts, 5,5);
CSingleStates(1,i).NP5_10=NPanalyse(CSingleStates(1,i).monocounts, 5,10);
CSingleStates(1,i).NP5_15=NPanalyse(CSingleStates(1,i).monocounts, 5,15);
CSingleStates(1,i).NP5_20=NPanalyse(CSingleStates(1,i).monocounts, 5,20);
CSingleStates(1,i).NP5_25=NPanalyse(CSingleStates(1,i).monocounts, 5,25);

 CSingleStates(1,i).NP8_12=NPanalyse(CSingleStates(1,i).monocounts, 8,12);
 CSingleStates(1,i).NP10_12=NPanalyse(CSingleStates(1,i).monocounts, 10, 12);
 CSingleStates(1,i).NP15_20=NPanalyse(CSingleStates(1,i).monocounts, 15, 20);
 CSingleStates(1,i).NP20_50=NPanalyse(CSingleStates(1,i).monocounts, 20, 50);
 CSingleStates(1,i).NP20_100=NPanalyse(CSingleStates(1,i).monocounts, 20, 100);
 CSingleStates(1,i).NP50_55=NPanalyse(CSingleStates(1,i).monocounts, 50, 55);

end

for i=2:101
NPtester.singleNPsteps2_101Full(:,i-1)=NPanalyse(NPtester.monocounts, i , 2554);
NPtester.singleNPsteps2_101Minus4(:,i-1)=NPanalyse(NPtester.monocounts, i , 2550);
NPtester.singleNPsteps2_1012000(:,i-1)=NPanalyse(NPtester.monocounts, i , 2000);
NPtester.singleNPsteps2_1002001(:,i-1)=NPanalyse(NPtester.monocounts, i , 2001);
end
for i=100:100:2000
NPtester.np100StepsFull(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2554);
NPtester.np100StepsMinus4(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2550);
NPtester.np100Steps2000(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2000);
NPtester.np100Steps2001(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2001);

end

for i=100:10:1010
NPtester.np10StepsFull(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2554);
NPtester.np10StepsMinus4(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2550);
NPtester.np10Steps2000(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2000);
NPtester.np10Steps2001(:,i/100)=NPanalyse(NPtester.monocounts(1,1), i , 2001);

end

    mono=NPtester.monocounts
for i=2:101
   
    g=i+20
    h=400+20*i 
    l=5+i
NPtester(i,1).singleNPsteps2i101_101(:,1)=NPanalyse(mono, i , 101);
NPtester(i,1).singleNPsteps20_21i121(:,1)=NPanalyse(mono, 20 , g);
NPtester(i,1).singleNPsteps440i2420_2500(:,1)=NPanalyse(mono, h, 2500);
NPtester(i,1).singleNPsteps7i108_500(:,1)=NPanalyse(mono, l , 500);
end

l=1
for k=1:length(GammaFRET)
for i=2:5:50
    np=NPanalyse(GammaFRET(1,k).monocounts, i , 100);
GammaFRET(1,k).np20StepsTW100(1:length(np),l)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 120);
GammaFRET(1,k).np20StepsTW120(1:length(np),l)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 150);
GammaFRET(1,k).np20StepsTW150(1:length(np),l)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 200);
GammaFRET(1,k).np20StepsTW200(1:length(np),l)=np;
l=l+1
end

for i=2:20
    clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 20);
GammaFRET(1,k).np19StepsTW20(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 30);
GammaFRET(1,k).np19StepsTW30(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 50);
GammaFRET(1,k).np19StepsTW50(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 100);
GammaFRET(1,k).np19StepsTW100(1:length(np),i-1)=np;

end
for i=2:10
    clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 10);
GammaFRET(1,k).np8StepsTW10(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 12);
GammaFRET(1,k).np8StepsTW12(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 15);
GammaFRET(1,k).np8StepsTW15(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, i , 20);
GammaFRET(1,k).np8StepsTW20(1:length(np),i-1)=np;

end
for i=5:15
    clear np
np=NPanalyse(GammaFRET(1,k).monocounts, 5 , i);
GammaFRET(1,k).np10StepsNP5(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, 6 , i);
GammaFRET(1,k).np10StepsNP6(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, 8 , i);
GammaFRET(1,k).np10StepsNP8(1:length(np),i-1)=np;
clear np
np=NPanalyse(GammaFRET(1,k).monocounts, 10 , i);
GammaFRET(1,k).np10StepsNP10(1:length(np),i-1)=np;

end
end






%%
for i=1:length(CSingleStates)

CSingleStates(1,i).

end
for i=1:length(CSingleStates)
check(i,1)=length(CSingleStates(1,i).NP2_Wmax);
check(i,2)=length(CSingleStates(1,i).NPmax_Wmax);
check(i,3)=length(CSingleStates(1,i).NP2max_Wmax);
check(i,4)=length(CSingleStates(1,i).NPmax_HWmax);
check(i,5)=length(CSingleStates(1,i).NP2max_HWmax);
end

for i=1:length(CSingleStates)
check2(i,1:2)=size(CSingleStates(1,i).NP2_20);
check2(i,3:4)=size(CSingleStates(1,i).NP10_200);
end
for i=1:length(CSingleStates)
check3(i,1)=length(CSingleStates(1,i).NP100_200);
check3(i,2)=length(CSingleStates(1,i).NP100_1000);
check3(i,3)=length(CSingleStates(1,i).NP200_Wmax);
check3(i,4)=length(CSingleStates(1,i).NPtotA_Wmax);
check3(i,5)=length(CSingleStates(1,i).NPtotD_Wmax);
check3(i,6)=length(CSingleStates(1,i).NPtotAD_Wmax);
check3(i,7)=length(CSingleStates(1,i).NPtotA_HWmax);
check3(i,8)=length(CSingleStates(1,i).NPtotD_HWmax);
check3(i,9)=length(CSingleStates(1,i).NPtotAD_HWmax);
end
%% NP successors
succesNP(:,1)=find(check3(:,2))
longest=max(check3(:,2))
NProbeEffi1001000=zeros(longest,length(succesNP));

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).NP100_1000);
NProbeEffi1001000(1:ende,i)=CSingleStates(1,succesNP(i,1)).NP100_1000;
end

longest=length(CSingleStates(1,36).eff100);
NProbeEffiRefCor=zeros(longest,length(succesNP));
for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).eff100);
NProbeEffiTW100RefCor(1:ende,i)=CSingleStates(1,succesNP(i,1)).eff100;
end


longest=length(CSingleStates(1,36).counts);
NProbeEffiRefCorCounts=zeros(longest,length(succesNP)*2);

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).counts);
NProbeEffiRefCorCounts(1:ende,i:i+1)=CSingleStates(1,succesNP(i,1)).counts;
end


longest=length(CSingleStates(1,36).monocounts);
NProbeEffiRefMono=zeros(longest,length(succesNP)*2);

for i=1:length(succesNP)
    ende=length(CSingleStates(1,succesNP(i,1)).monocounts);
NProbeEffiRefMono(1:ende,i:i+1)=CSingleStates(1,succesNP(i,1)).monocounts;
end

%% 

%% Export

for i=1:length(CSingleStates)
ende=length(CSingleStates(1,succesNP(i,1)).NP100_1000);
a(:,i)=NProbeEffi1001000(1:ende,i);
name=['stateFRETnp-',num2str(succesNP(i,1)),'_org',CSingleStates(1,succesNP(i,1)).names(17:20),'.dat'];
save (name, 'a', '-ascii', '-double')
clear a
clear name
end

for i=1:length(CSingleStates)
...
end


NPtester.maxCount=max(max(CSingleStates(1,i).counts));
    maxW=length(CSingleStates(1,i).monocounts);
    maxND=find(CSingleState(1,i).monocounts(:,1))
    maxNA=find(CSingleState(1,i).monocounts(:,2))

k=0
for s=1:3
    figure;
        for i=1:30
    subplot(10,3,i)
    plot(CSingleStates(1,i+k).eff100)
    set(gca,'xtick',[],'ytick',[], 'YColor','b');
    title([num2str(k+i) ' part ' CSingleStates(1,i).part])
    xyPos=get(gca,'Position')-[0.09 -0.05 0 0];
    xyPos(1,3:4)=[0.29 0.1]
    set(gca, 'Position',xyPos,...
           'XLim',[1,length(CSingleStates(1,i+k).eff100)]);
        end
    k=k+30;
    
end

for i=1:24
    name=[goodTSCFRET(1,i).names(1:20) '_cor_mono.dat']
    mono=goodTSCFRET(3,i).monocounts;
    save(name, 'mono' ,'-ASCII')
    clear mono
end 
%% --------------Histograms
for i=1:169
n1000fret(1,i).ints10000=timewindow(uFRET(1,i).counts,10000)
end
for i=1:169
n1000fret(1,i).eff10000=effer(n1000fret(1,i).ints10000);
end


anf=1
for i=1:171
    ende=length(uFRET(1,i).eff10);
    n1000fret(1,i).eff1000=effer(n1000fret(1,i).int1000);
end

anf=1
for i=1:169
    ende=length(n1000fret(1,i).eff1000);
    megamonster1000(anf:anf+ende-1,1)=n1000fret(1,i).eff1000(1:ende,1);
    anf=anf+ende+1
end
anf=1
for i=1:169
    ende=length(n1000fret(1,i).eff10000);
    megamonster10000(anf:anf+ende-1,1)=n1000fret(1,i).eff10000(1:ende,1);
    anf=anf+ende+1
end



    hi

for i=1:24
    ende=goodTSCFRET(1,i).A_bleached;
    monster20(anf:anf+ende-1,1)=goodTSCFRET(1,i).eff20(1:ende,1);
    anf=anf+ende+1
end
    histc10tw5tel=histc(monster10,0:0.2:1)
histc10tw10tel=histc(monster10,0:0.1:1)
histc10tw40tel=histc(monster10,0:0.025:1)
histc10tw100tel=histc(monster10,0:0.01:1)
histc10tw1000tel=histc(monster10,0:0.001:1)
bar(0:0.025:1,histc10tw40tel)
bar(0:0.01:1,histc10tw100tel)
bar(0:0.001:1,histc10tw1000tel)
%-------
Muhistc50tw100tel=histc(megamonster50u,0:0.01:1)
Muhistc10tw100tel=histc(megamonster10u,0:0.01:1)
Muhistc1000tw100tel=histc(megamonster1000,0:0.01:1)
Muhistc100tw100tel=histc(megamonster100u,0:0.01:1)

bar(0:0.1:1,Mhistc20tw10tel)
bar(0:0.01:1,Muhistc10tw100tel)

bar(0:0.01:1,Muhistc1000tw100tel)
figure;
bar(0.01:0.01:1,histc10000tw100tel(2:101))
histc10000tw100tel=histc(megamonster10000,0:0.01:1)

histc50tw10tel=histc(monster50,0:0.1:1)
histc50tw100tel=histc(monster50,0:0.01:1)

histc100tw10tel=histc(monster100,0:0.1:1)
histc100tw100tel=histc(monster100,0:0.01:1)
        megamonster1000u(anf:anf+ende-1,1)=n1000fret(1,i).eff10(1:ende,1);
    anf=anf+ende+1