%% Building Single State Trajectory Vector
k=0
anf=1
for i=1:13
    
CSingleStates(i).gamma2=goodTSCFRET(1,i).psG2;
CSingleStates(i).bg=goodTSCFRET(1,i).bg;
CSingleStates(i).cross=goodTSCFRET(1,i).cross;


CSingleStates(i).counts=goodTSCFRET(3,i).counts(1:goodTSCFRET(1,i).A_bleached,1:2);
CSingleStates(i).names=goodTSCFRET(3,i).names;
CSingleStates(i).part='1/1';
end

k=0
anf=1
for i=14:18
CSingleStates(i).gamma2=goodTSCFRET(1,14).psG2;
CSingleStates(i).bg=goodTSCFRET(1,14).bg;
CSingleStates(i).cross=goodTSCFRET(1,14).cross;

    k=k+1
    %ende=cursor_info(1,end+1-k).DataIndex;
    ende=singlelength(i,1);
CSingleStates(1,i).counts=goodTSCFRET(3,14).counts(anf:anf+ende-1,1:2);
CSingleStates(1,i).names=goodTSCFRET(3,14).names;
CSingleStates(1,i).part=[num2str(k) '/' num2str(5)];
anf=anf+ende;
end

CSingleStates(19).counts=goodTSCFRET(3,15).counts(1:goodTSCFRET(1,15).A_bleached,1:2);
CSingleStates(19).names=goodTSCFRET(3,15).names;
CSingleStates(19).part='1/1';
CSingleStates(19).gamma2=goodTSCFRET(1,19).psG2;
CSingleStates(19).bg=goodTSCFRET(1,19).bg;
CSingleStates(19).cross=goodTSCFRET(1,19).cross;


k=0
anf=1
for i=20:22
    CSingleStates(i).gamma2=goodTSCFRET(1,16).psG2;
CSingleStates(i).bg=goodTSCFRET(1,16).bg;
CSingleStates(i).cross=goodTSCFRET(1,16).cross;
end
    k=k+1
    ende=singlelength(i,1);
    %ende=cursor_info(1,end+1-k).DataIndex;
CSingleStates(1,i).counts=goodTSCFRET(3,16).counts(anf:anf+ende-1,1:2);
CSingleStates(1,i).names=goodTSCFRET(3,16).names;
CSingleStates(1,i).part=[num2str(k) '/3'];
anf=anf+ende;
end
CSingleStates(23).counts=goodTSCFRET(3,17).counts(1:goodTSCFRET(1,17).A_bleached,1:2);
CSingleStates(23).names=goodTSCFRET(3,17).names;
CSingleStates(23).part='1/1';


k=0
anf=1
for i=24:26
    k=k+1
    ende=singlelength(i,1);
%    ende=cursor_info(1,end+1-k).DataIndex;
CSingleStates(1,i).counts=goodTSCFRET(3,18).counts(anf:anf+ende-1,1:2);
CSingleStates(1,i).names=goodTSCFRET(3,18).names;
CSingleStates(1,i).part=[num2str(k) '/3'];
anf=anf+ende;
end
CSingleStates(27).counts=goodTSCFRET(3,19).counts(1:goodTSCFRET(1,19).A_bleached,1:2);
CSingleStates(27).names=goodTSCFRET(3,19).names;
CSingleStates(27).part='1/1';
CSingleStates(28).counts=goodTSCFRET(3,20).counts(1:goodTSCFRET(1,20).A_bleached,1:2);
CSingleStates(28).names=goodTSCFRET(3,20).names;
CSingleStates(28).part='1/1';

CSingleStates(29).counts=goodTSCFRET(3,21).counts(1:goodTSCFRET(1,21).A_bleached,1:2);
CSingleStates(29).names=goodTSCFRET(3,21).names;
CSingleStates(29).part='1/1';
k=0
anf=1
for i=30:34
    k=k+1
    ende=singlelength(i,1);
%    ende=cursor_info(1,end+1-k).DataIndex;
CSingleStates(1,i).counts=goodTSCFRET(3,22).counts(anf:anf+ende-1,1:2);
CSingleStates(1,i).names=goodTSCFRET(3,22).names;
CSingleStates(1,i).part=[num2str(k) '/5'];
anf=anf+ende;
end
CSingleStates(35).counts=goodTSCFRET(3,23).counts(1:goodTSCFRET(1,23).A_bleached,1:2);
CSingleStates(35).names=goodTSCFRET(3,23).names;
CSingleStates(35).part='1/1';
CSingleStates(36).counts=goodTSCFRET(3,24).counts(1:goodTSCFRET(1,24).A_bleached,1:2);
CSingleStates(36).names=goodTSCFRET(3,24).names;
CSingleStates(36).part='1/1';
%----------------- später noch für gut befunden:
addCFRET(1,1)=mediumCFRET(1,3);
addCFRET(1,2)=mediumCFRET(1,4);
addCFRET(1,3)=mediumCFRET(1,6);
addCFRET(1,4)=mediumCFRET(1,7);
addCFRET(1,5)=mediumCFRET(1,10);
addCFRET(1,6)=mediumCFRET(1,18);
addCFRET(1,7)=mediumCFRET(1,19);
addCFRET(1,8)=mediumCFRET(1,20);
addCFRET(1,9)=mediumCFRET(1,24);
addCFRET(1,10)=mediumCFRET(1,27);
addCFRET(1,11)=mediumCFRET(1,28);
addCFRET(1,12)=mediumCFRET(1,30);
addCFRET(1,13)=mediumCFRET(1,31);
addCFRET(1,14)=mediumCFRET(1,32);
addCFRET(1,15)=mediumCFRET(1,33);
addCFRET(1,16)=mediumCFRET(1,36);
addCFRET(1,17)=mediumCFRET(1,39);
addCFRET(1,18)=mediumCFRET(1,43);
addCFRET(1,19)=mediumCFRET(1,50);
addCFRET(1,20)=mediumCFRET(1,52);
addCFRET(1,21)=mediumCFRET(1,60);
addCFRET(1,22).counts=oxyFRET(1,7).counts;
addCFRET(1,22).names=oxyFRET(1,7).names;
addCFRET(1,22).ints10=oxyFRET(1,7).ints10;
addCFRET(1,22).ints20=oxyFRET(1,7).ints20;
addCFRET(1,22).ints50=oxyFRET(1,7).ints50;
addCFRET(1,22).ints100=oxyFRET(1,7).ints100;
addCFRET(1,22).A_bleached =oxyFRET(1,7).A_bleached;
addCFRET(1,22).D_bleached=oxyFRET(1,7).D_bleached;
addCFRET(1,23).counts=oxyFRET(1,13).counts;
addCFRET(1,23).names=oxyFRET(1,13).names;
addCFRET(1,23).ints10=oxyFRET(1,13).ints10;
addCFRET(1,23).ints20=oxyFRET(1,13).ints20;
addCFRET(1,23).ints50=oxyFRET(1,13).ints50;
addCFRET(1,23).ints100=oxyFRET(1,13).ints100;
addCFRET(1,23).A_bleached =oxyFRET(1,13).A_bleached;
addCFRET(1,23).D_bleached=oxyFRET(1,13).D_bleached;
addCFRET(1,24).counts=oxyFRET(1,75).counts;
addCFRET(1,24).names=oxyFRET(1,75).names;
addCFRET(1,24).ints10=oxyFRET(1,75).ints10;
addCFRET(1,24).ints20=oxyFRET(1,75).ints20;
addCFRET(1,24).ints50=oxyFRET(1,75).ints50;
addCFRET(1,24).ints100=oxyFRET(1,75).ints100;
addCFRET(1,24).A_bleached =oxyFRET(1,75).A_bleached;
addCFRET(1,24).D_bleached=oxyFRET(1,75).D_bleached;
addCFRET(1,25).counts=mediumCFRET(1,73).counts;
addCFRET(1,25).names=mediumCFRET(1,73).names;
addCFRET(1,25).ints10=mediumCFRET(1,73).ints10;
addCFRET(1,25).ints20=mediumCFRET(1,73).ints20;
addCFRET(1,25).ints50=mediumCFRET(1,73).ints50;
addCFRET(1,25).ints100=mediumCFRET(1,73).ints100;
addCFRET(1,25).A_bleached =mediumCFRET(1,73).A_bleached;
addCFRET(1,25).D_bleached=mediumCFRET(1,73).D_bleached;


for i=1:23
    mediumNames(i,:)=addCFRET(1,i).names
end
addCFRET=errorcalc(addCFRET)
addCFRET=errorcorr(addCFRET);

for i=1:6
    



k=0
anf=1
for i=37:41
%     k=k+1
%     ende=cursor_info(1,end+1-k).DataIndex;
%     %ende=singlelength(i,1);
%     CSingleStates(1,i).counts=addCFRET(3,1).counts(anf:ende,1:2);
%     CSingleStates(1,i).names=mediumCFRET(1,1).names;
% CSingleStates(1,i).part=[num2str(k) '/6'];
% anf=ende+1;
a(i)=length(CSingleStates(1,i).counts)
end

CSingleStates(1,42).counts=addCFRET(3,1).counts(37372:addCFRET(1,1).A_bleached-10,1:2);
CSingleStates(1,43).counts=addCFRET(3,2).counts(1:3855,1:2);
CSingleStates(1,44).counts=addCFRET(3,3).counts(1:12470,1:2);
CSingleStates(1,45).counts=addCFRET(3,4).counts(1:1912,1:2);
CSingleStates(1,46).counts=addCFRET(3,5).counts(1:cursor_info(7).DataIndex,1:2);
CSingleStates(1,47).counts=addCFRET(3,5).counts(cursor_info(7).DataIndex:cursor_info(6).DataIndex,1:2);

CSingleStates(1,48).counts=addCFRET(3,6).counts(1:addCFRET(1,6).A_bleached-10,1:2);
CSingleStates(1,49).counts=addCFRET(3,7).counts(1:addCFRET(1,7).A_bleached-10,1:2);

CSingleStates(1,50).counts=addCFRET(3,8).counts(1:cursor_info(5).DataIndex,1:2);
CSingleStates(1,51).counts=addCFRET(3,8).counts(cursor_info(5).DataIndex:cursor_info(4).DataIndex,1:2);
CSingleStates(1,52).counts=addCFRET(3,8).counts(cursor_info(4).DataIndex:cursor_info(3).DataIndex,1:2);

CSingleStates(1,53).counts=addCFRET(3,25).counts(1:addCFRET(1,25).A_bleached,1:2);
CSingleStates(1,54).counts=addCFRET(3,9).counts(1:addCFRET(1,9).A_bleached-10,1:2);

CSingleStates(1,55).counts=addCFRET(3,10).counts(1:cursor_info(2).DataIndex,1:2);
CSingleStates(1,56).counts=addCFRET(3,10).counts(cursor_info(2).DataIndex:cursor_info(1).DataIndex,1:2);
CSingleStates(1,57).counts=addCFRET(3,10).counts(length(CSingleStates(1,55).counts)+length(CSingleStates(1,56).counts):addCFRET(1,10).A_bleached-10,1:2);

CSingleStates(1,58).counts=addCFRET(3,11).counts(1:addCFRET(1,11).A_bleached-10,1:2);
CSingleStates(1,59).counts=addCFRET(3,12).counts(1:addCFRET(1,12).A_bleached-10,1:2);
CSingleStates(1,60).counts=addCFRET(3,13).counts(1:addCFRET(1,13).A_bleached-10,1:2);
CSingleStates(1,61).counts=addCFRET(3,14).counts(1:addCFRET(1,14).A_bleached-10,1:2);
CSingleStates(1,62).counts=addCFRET(3,15).counts(1:addCFRET(1,15).A_bleached-10,1:2);

CSingleStates(1,63).counts=addCFRET(3,16).counts(1:cursor_info(4).DataIndex,1:2);
CSingleStates(1,64).counts=addCFRET(3,16).counts(cursor_info(4).DataIndex:cursor_info(3).DataIndex,1:2);
CSingleStates(1,65).counts=addCFRET(3,16).counts(length(CSingleStates(1,63).counts)+length(CSingleStates(1,64).counts):addCFRET(1,16).A_bleached-10,1:2);

CSingleStates(1,66).counts=addCFRET(3,17).counts(1:addCFRET(1,17).A_bleached-10,1:2);
CSingleStates(1,67).counts=addCFRET(3,18).counts(1:addCFRET(1,18).A_bleached-10,1:2);
CSingleStates(1,68).counts=addCFRET(3,19).counts(1:addCFRET(1,19).A_bleached-10,1:2);

CSingleStates(1,69).counts=addCFRET(3,20).counts(1:cursor_info(2).DataIndex,1:2);
CSingleStates(1,70).counts=addCFRET(3,20).counts(cursor_info(2).DataIndex:cursor_info(1).DataIndex,1:2);
%CSingleStates(1,71).counts=addCFRET(3,20).counts(cursor_info(1).DataIndex:addCFRET(1,20).A_bleached-10,1:2);
CSingleStates(1,71).counts=addCFRET(3,20).counts(length(CSingleStates(1,70).counts)+length(CSingleStates(1,69).counts):addCFRET(1,20).A_bleached-10,1:2);


CSingleStates(1,72).counts=addCFRET(3,21).counts(1:addCFRET(1,21).A_bleached-20,1:2);

CSingleStates(1,73).counts=addCFRET(3,22).counts(1:cursor_info(5).DataIndex,1:2);
CSingleStates(1,74).counts=addCFRET(3,22).counts(cursor_info(1,5).DataIndex:cursor_info(4).DataIndex,1:2);
CSingleStates(1,75).counts=addCFRET(3,22).counts(cursor_info(1,4).DataIndex:cursor_info(1,3).DataIndex,1:2);
CSingleStates(1,76).counts=addCFRET(3,22).counts(cursor_info(1,3).DataIndex:cursor_info(1,2).DataIndex,1:2);
CSingleStates(1,77).counts=addCFRET(3,22).counts(cursor_info(2).DataIndex:cursor_info(1,1).DataIndex,1:2);
CSingleStates(1,78).counts=addCFRET(3,22).counts(cursor_info(1).DataIndex:addCFRET(1,22).A_bleached-10,1:2);


CSingleStates(1,79).counts=addCFRET(3,24).counts(1:13449,1:2);
CSingleStates(1,79).names=oxyFRET(1,75).names;
CSingleStates(1,79).part=[ '1/3'];
CSingleStates(1,80).counts=addCFRET(3,24).counts(13449:14625,1:2);
CSingleStates(1,80).names=oxyFRET(1,75).names;
CSingleStates(1,80).part=[ '2/3'];
CSingleStates(1,81).counts=addCFRET(3,24).counts(14625:29700,1:2);
CSingleStates(1,81).names=oxyFRET(1,75).names;
CSingleStates(1,81).part=[ '3/3'];

CSingleStates(1,82).counts=addCFRET(3,23).counts(1:7500,1:2);
CSingleStates(1,82).names=oxyFRET(1,13).names;
CSingleStates(1,82).part=[ '1/3'];
CSingleStates(1,83).counts=addCFRET(3,23).counts(7501:7946,1:2);
CSingleStates(1,83).names=oxyFRET(1,13).names;
CSingleStates(1,83).part=[ '2/3'];
CSingleStates(1,84).counts=addCFRET(3,23).counts(7946:10990,1:2);
CSingleStates(1,84).names=oxyFRET(1,13).names;
CSingleStates(1,84).part=[ '3/3'];
anf=ende+anf;
end

k=0
anf=1
for i=1:84
    k=k+1
    %ende=cursor_info(1,end+1-k).DataIndex;
    ende=singlelength(i,1);
CSingleStates(1,i).counts=oxyFRET(1,).counts(anf:anf+ende-1,1:2);
CSingleStates(1,i).names=oxyFRET(1,13).names;
CSingleStates(1,i).part=[num2str(k) '/3'];
anf=ende;
end

% --------Tests--------
for i=1:84
    TestCSS(i,1)=mean(CSingleStates(1,i).counts(:,2));
   % TestCSS(i,2)=mean(CSingleStatesPrev(1,i).counts(:,2));
    TestCSS(i,2)=sqrt(var(CSingleStates(1,i).counts(:,2)));   
   % TestCSS(i,4)=var(CSingleStatesPrev(1,i).counts(:,2));
end

mean(oxyFRET(2,34).counts(:,2))
mean(addCFRET(3,1).counts(:,2))
mean(CSingleStates(1,37).counts(:,2))
