open(vid)

theta_1=2*Du*tau/delta;
theta_2=2*Di*tau/delta;
minAx=0;
maxAx=K;
griglia=L/delta; %numeri pari
vu=sqrt(Du*p/2);
vi=sqrt(Di*(beta*K-q)/2);

for i=1:10:T_pde+1
    clf
    plot((0:griglia)*delta,U_plot(:,i)/delta,'LineWidth',1)
    hold on
    plot(x,u1(i,:),'--')
    hold on
    yline(q/beta)
    hold on
    xline(L/2+Ru+(i-1)*vu,'--')
    hold on
    xline(L/2-Ru-(i-1)*vu,'--')
    hold on
    plot((0:griglia)*delta,(U_plot(:,i)+I_plot(:,i))/delta)
    plot((0:griglia)*delta,I_plot(:,i)/delta,'LineWidth',1)
    hold on
    plot(x,u2(i,:),'--')
    hold on
    yline(p*(beta*K-q)/beta/(beta*K+p))
    axis([0 griglia*delta minAx maxAx])
    title('Cellule infette', 'q='+string(q)+', \beta='+string(beta)+', \theta_2='+string(theta_2)+...
        ', \delta='+string(delta)+', \tau='+string(tau))
    legend('Agenti','PDE')

    frame=getframe(h);
    writeVideo(vid,frame);
end


close(vid)