clear
dt=20;
timespan=500;
rate1=0.5;
rate2=-0.1;
B2=[40,200,450];
timebins=0:dt:timespan;
jmax=numel(timebins);
t1=0;
t2=0;
max_fault=max([rate1,rate2])*timespan+30;
min_fault=min([rate1,rate2])*timespan-30;
figure(1)
clf
F(jmax) = struct('cdata',[],'colormap',[]);
hold on
plot([0 0],[min_fault max_fault],'-k')
p1=plot([-30 0],[t1 t1],'-b');
p2=plot([0 30],[t2 t2],'-b');
ylim([min_fault max_fault ])
for j=1:jmax
time=timebins(j);
t1=(time*rate1);
t2=(time*rate2);
pause(0.8)
set(p1,'ydata',[t1 t1])
set(p2,'ydata',[t2 t2])
for i=1:numel(B2)
B=B2(i);
clear t3 t4
if time==B
t3=(time-B)*rate1;
t4=(time-B)*rate2;
p3=plot([-30 0],[t3 t3],'-');
p4=plot([0 30],[t4 t4],'-');
elseif time>=B
t3=(time-B)*rate1;
t4=(time-B)*rate2;
set(p3,'ydata',[t3 t3])
set(p4,'ydata',[t4 t4])
drawnow
end
end
end