h0=1; g=1; set(gca,'FontSize',18) c0=sqrt(g*h0); xmin=-20; xmax=20; t_range=0.01:0.5:10.01; delete video.gif %have to delete old one so new one shows up for j=1:length(t_range) t=t_range(j); xL=xmin:0.01:(-c0*t); xC=(-c0*t):0.01:(2*c0*t); xR=(2*c0*t):0.01:xmax; hL=h0*ones(size(xL)); hC=h0/9.*(2-xC./(c0*t)).^2; hR=zeros(size(xR)); x=[xL,xC,xR]; h=[hL,hC,hR]; plot(x,h,'LineWidth',2) xlim([-20,20]) ylim([0,2*h0]) grid on title(['t=',num2str(t_range(j) - 0.01,'%1.1f')]) ylabel('h') xlabel('x') pause(0.1) gif_add_frame(gcf,'video.gif',1); end