nextState(1,1)=0;
Slength(1,1)=0;
Sendings(1,2)=find(AllStateTrajectory(:,2)==0,1,'last');
for i=2:261
    nextState(i,1)=AllStateTrajectory(Sendings(i-1,2)+1,2);
    Sendings(i,1)=find(AllStateTrajectory(:,2)==nextState(i-1,1),1,'first');
    Sendings(i,2)=find(AllStateTrajectory(:,2)==nextState(i-1,1),1,'last');
    Slength(i-1,1)=Sendings(i,2)-Sendings(i,1);
    Slength(i-1,2)=nextState(i,1);
end

[length260(:,1) length260(:,2)]=sort(Slength(:,1));

for i=1:37
    found=find(AllStateTrajectory(:,2)==34)
    AllStateTrajectory(found:end-1,:)=AllStateTrajectory(found+1:end,:);
end


    found(1,2)=find(AllStateTrajectory(:,2)==35,1,'last');
    found(1,1)=find(AllStateTrajectory(:,2)==35,1,'first');
    dur=found(1,2)-found(1,1);
    AllStateTrajectory(found(1,1):end-dur,:)=AllStateTrajectory(found(1,2):end,:);


 AllStateTrajectory=AllStateTrajectory(1:end-dur,:);





