
function SingleStates=Singelizer(inFRET, SortedStateChanges, from)
%% Creates the structured array $SingleStates of all Trajectories (row) and States (col)
%  Trajectories $from are pointer to Data collection structure nuFRET which
%  to be statelized
%  visually defined states in $Schange are divided into $SingleStates

nstreams = size(SortedStateChanges,1);
last=zeros(nstreams+1,1);
for i=1:nstreams
   
    last(i+1,1)=find(SortedStateChanges(i,:)==0,1);
    if isfield(inFRET, 'A_bleached')==0
        out=length(inFRET(1,from(1,i)).counts);
    else
    out=inFRET(1,from(1,i)).A_bleached;
    end
    SortedStateChanges(i,last(i+1,1))=out;
    
    anf=1;
    SingleStates=struct([]);
    from(1,i)

   for l=1:last(i+1)
        k=l+sum(last(1:i));
                SingleStates(1,k).names=inFRET(1,from(1,i)).names;
        SingleStates(1,k).part=[num2str(l),'/',num2str(last(i+1,1))];
        ende=SortedStateChanges(i,l)-20;
        SingleStates(1,k).counts(:,1:2)=inFRET(1,from(1,i)).counts(anf:ende,1:2) ;    
       % SingleStates(1,k).monocounts(:,1:2)=inFRET(1,from(1,i)).monocounts(anf:ende,1:2) ; 
        anf=ende+40;
   end
        
end
