function [H_new zero range eigvec mi]=update_hyperstate(H_old,zero, range, eigvec, mi,n_grid,H_full)
dim=2;

next_u=zeros(1,size(H_old,2));

step=[1; n_grid];
stav1=zeros(dim,1);

H_new=generate_trajectories(H_old,mi);
    
for i=2:size(H_new,1)
    pom(:,:)=H_new(i,:,:);
    
   % plot(H_new(i,:,1),H_new(i,:,2),'g.'); hold on
    
    [H_new(i,:,:) next_zero next_range next_eigvec]=make_box3(pom); %rovnomerne rozmisti body v zasazenem regionu
    
    if (H_full)  %kopirovani stareho mi* do H_new  
        for j=1:size(H_new,2)
             stav(1,1)=H_new(i,j,1)-zero(i,1);   
             stav(1,2)=H_new(i,j,2)-zero(i,2);   
             % for p=1:dim
            %     stav1(p)=(stav(1)*eigvec(i,1,p)+stav(2)*eigvec(i,2,p))*range(i,p)*n_grid-1+1;
            % end
            stav1=stav.*range(i,:)*(n_grid-1)+1;
            index=min(max(round(stav1),1),n_grid)-[0 1];
            index=index*step;
                                    
             next_u(j)=mi(i,index);
        end
        
        for j=1:size(H_new,2)
            mi(i,j)= next_u(j);
        end
    end
    
    zero(i,:)=next_zero;
    range(i,:)=next_range;
    eigvec(i,:,:)=next_eigvec;
end
end