function SortedStateChanges=Statelizer(state_INFO)
%% Creates a Trajectory/State Matrix containing statechange points (cols)
%% for every trajectory (rows)

k=1;
l=1;
DataTips=length(state_INFO);


for i=1:DataTips
    current_trajectory=state_INFO(1,DataTips+1-i).Target;
    StateChanges(k,l)=state_INFO(1,DataTips+1-i).Position(1,1); 
    l=l+1;
    
    if i==DataTips && state_INFO(1,2).Target==current_trajectory
      %  StateChanges(k,l)=state_INFO(1,DataTips+1-i).DataIndex;
        
    elseif i==DataTips && state_INFO(1,2).Target~=current_trajectory
        StateChanges(k,1)=state_INFO(1,1).Position(1,1);

    
    elseif state_INFO(1,DataTips-i).Target==current_trajectory
        StateChanges(k,l)=state_INFO(1,DataTips+1-i).Position(1,1);
        
    elseif state_INFO(1,DataTips-i).Target ~= current_trajectory
        l=1;
        k=k+1;
        StateChanges(k,l)=state_INFO(1,DataTips+1-i).Position(1,1);
    
   

    end
end

PreSorted=sort(StateChanges,2,'ascend');
T=size(StateChanges,1);
for i=1:T
    row=find(PreSorted(i,:));
    e=length(row);
    SortedStateChanges(i,1:e)=PreSorted(i,row(1):row(end));
    
end

    