%EXTEM
k=1;

%INTEM
o=1;

%FIBTEM
v=1;

%APTEM
r=1;

%Skalierung Plot
p=65;

%Videl erstellen
clot_EXTEM=num2cell(clot_ex{:,k}); 
time_EXTEM=num2cell(time_ex{:,k}); 
clot_INTEM=num2cell(clot_in{:,o}); 
time_INTEM=num2cell(time_in{:,o});
clot_FIBTEM=num2cell(clot_fib{:,v}); 
time_FIBTEM=num2cell(time_fib{:,v});
clot_APTEM=num2cell(clot_ap{:,v}); 
time_APTEM=num2cell(time_ap{:,v});

n=length(clot_EXTEM);



for i=1:n
    %EXTEM
    y_cell_EXTEM=clot_EXTEM(1:i); 
    x_cell_EXTEM=time_EXTEM(1:i);
    y_EXTEM=(cell2mat(y_cell_EXTEM)-1.5);
    x_EXTEM=cell2mat(x_cell_EXTEM)/60;
    %INTEM
    y_cell_INTEM=clot_INTEM(1:i); 
    x_cell_INTEM=time_INTEM(1:i);
    y_INTEM=(cell2mat(y_cell_INTEM)-1.5);
    x_INTEM=cell2mat(x_cell_INTEM)/60;
    %FIBTEM
    y_cell_FIBTEM=clot_FIBTEM(1:i); 
    x_cell_FIBTEM=time_FIBTEM(1:i);
    y_FIBTEM=(cell2mat(y_cell_FIBTEM)-1.5);
    x_FIBTEM=cell2mat(x_cell_FIBTEM)/60;
    %APTEM
    y_cell_APTEM=clot_APTEM(1:i); 
    x_cell_APTEM=time_APTEM(1:i);
    y_APTEM=(cell2mat(y_cell_APTEM)-1.5);
    x_APTEM=cell2mat(x_cell_APTEM)/60;
    
 
  if x_EXTEM(end)<=(CT_extem(k))/60
        x_EXTEM_=x_EXTEM;
        y_EXTEM_=y_EXTEM;
  end
  if x_INTEM(end)<=(CT_intem(o))/60
        x_INTEM_=x_INTEM;
        y_INTEM_=y_INTEM;
  end
  if x_FIBTEM(end)<=(CT_fibtem(v))/60
        x_FIBTEM_=x_FIBTEM;
        y_FIBTEM_=y_FIBTEM;
  end
  if x_APTEM(end)<=(CT_fibtem(r))/60
        x_APTEM_=x_APTEM;
        y_APTEM_=y_APTEM;
  end
  
  
  %EXTEM
     if x_EXTEM(end)<=CT_extem(k)/60
     subplot(2,2,1);
     plot(x_EXTEM_,y_EXTEM_,'m','LineWidth', 2);
     hold on
     plot(x_EXTEM_,-y_EXTEM_,'m');
     axis([0 35 -p p]);
     title('EXTEM');
     %title('EXTEM','position', [32, 75]); 
     xlabel('time [min]'); 
     ylabel('clot [mm]');
     grid on
     end
  %INTEM
     if x_INTEM(end)<=CT_intem(o)/60
     subplot(2,2,3);
     plot(x_INTEM_,y_INTEM_,'m','LineWidth', 2);
     hold on
     plot(x_INTEM_,-y_INTEM_,'m');
     axis([0 35 -p p]);
     title('INTEM');
     %title('INTEM','position', [32, 75]); 
     xlabel('time [min]'); 
     ylabel('clot [mm]');
     grid on
     end 
  %FIBTEM
  if x_FIBTEM(end)<=CT_fibtem(v)/60
     subplot(2,2,2);
     plot(x_FIBTEM_,y_FIBTEM_,'m','LineWidth', 2);
     hold on
     plot(x_FIBTEM_,-y_FIBTEM_,'m');
     axis([0 35 -p p]);
     title('FIBTEM');
     %title('FIBTEM','position', [32, 75]); 
     xlabel('time [min]'); 
     ylabel('clot [mm]');
     grid on
  end
  %APTEM
  if x_APTEM(end)<=CT_aptem(r)/60
     subplot(2,2,4);
     plot(x_APTEM_,y_APTEM_,'m','LineWidth', 2);
     hold on
     plot(x_APTEM_,-y_APTEM_,'m');
     axis([0 35 -p p]);
     title('APTEM');
     %title('FIBTEM','position', [32, 75]); 
     xlabel('time [min]'); 
     ylabel('clot [mm]');
     grid on
     end
  
  %Ab hier: CLOT
    if x_EXTEM(end)>(CT_extem(k))/60 && y_EXTEM(end)<=20
        subplot(2,2,1)  
        x_EXTEM_=x_EXTEM;
        y_EXTEM_=y_EXTEM;
        length_EXTEM_x=length(x_EXTEM);
        length_EXTEM_y=length(y_EXTEM);
        fill([x_EXTEM';x_EXTEM'],[y_EXTEM';-y_EXTEM'],'m','edgecolor','m')
    end
    if x_INTEM(end)>(CT_intem(o))/60 && y_INTEM(end)<=20
        subplot(2,2,3)  
        x_INTEM_=x_INTEM;
        y_INTEM_=y_INTEM;
        length_INTEM_x=length(x_INTEM);
        length_INTEM_y=length(y_INTEM);
        fill([x_INTEM';x_INTEM'],[y_INTEM';-y_INTEM'],'m','edgecolor','m')
    end
    if x_FIBTEM(end)>(CT_fibtem(v))/60 && y_FIBTEM(end)<=20
        subplot(2,2,2)  
        x_FIBTEM_=x_FIBTEM;
        y_FIBTEM_=y_FIBTEM;
        length_FIBTEM_x=length(x_FIBTEM);
        length_FIBTEM_y=length(y_FIBTEM);
        fill([x_FIBTEM';x_FIBTEM'],[y_FIBTEM';-y_FIBTEM'],'m','edgecolor','m')
    end
    if x_APTEM(end)>(CT_aptem(r))/60 && y_APTEM(end)<=20
        subplot(2,2,4)  
        x_APTEM_=x_APTEM;
        y_APTEM_=y_APTEM;
        length_APTEM_x=length(x_APTEM);
        length_APTEM_y=length(y_APTEM);
        fill([x_APTEM';x_APTEM'],[y_APTEM';-y_APTEM'],'m','edgecolor','m')
    end
    
    if x_EXTEM(end)>(CT_extem(k))/60 && y_EXTEM(end)>20
        x_EXTEM__=x_EXTEM(length_EXTEM_x:end);
        y_EXTEM__=y_EXTEM(length_EXTEM_y:end);
        subplot(2,2,1)  
        fill([x_EXTEM_';x_EXTEM_'],[y_EXTEM_';-y_EXTEM_'],'m','edgecolor','m')
        fill([x_EXTEM__';x_EXTEM__'],[y_EXTEM__';-y_EXTEM__'],'b','edgecolor','b')
    end
    if x_INTEM(end)>(CT_intem(o))/60 && y_INTEM(end)>20
        x_INTEM__=x_INTEM(length_INTEM_x:end);
        y_INTEM__=y_INTEM(length_INTEM_y:end);
        subplot(2,2,3)  
        fill([x_INTEM_';x_INTEM_'],[y_INTEM_';-y_INTEM_'],'m','edgecolor','m')
        fill([x_INTEM__';x_INTEM__'],[y_INTEM__';-y_INTEM__'],'b','edgecolor','b')
    end
    if x_FIBTEM(end)>(CT_fibtem(v))/60 && y_FIBTEM(end)>20
        x_FIBTEM__=x_FIBTEM(length_FIBTEM_x:end);
        y_FIBTEM__=y_FIBTEM(length_FIBTEM_y:end);
        subplot(2,2,2)  
        fill([x_FIBTEM_';x_FIBTEM_'],[y_FIBTEM_';-y_FIBTEM_'],'b','edgecolor','b')
        fill([x_FIBTEM__';x_FIBTEM__'],[y_FIBTEM__';-y_FIBTEM__'],'b','edgecolor','b')
    end
    if x_APTEM(end)>(CT_aptem(r))/60 && y_APTEM(end)>20
        x_APTEM__=x_APTEM(length_APTEM_x:end);
        y_APTEM__=y_APTEM(length_APTEM_y:end);
        subplot(2,2,4)  
        fill([x_APTEM_';x_APTEM_'],[y_APTEM_';-y_APTEM_'],'m','edgecolor','m')
        fill([x_APTEM__';x_APTEM__'],[y_APTEM__';-y_APTEM__'],'b','edgecolor','b')
    end
    
      %if x_EXTEM(end)>(CT_extem(k))/60+31
      if x_EXTEM(end)>35;
        break
      end
  
    M(i)=getframe(gcf);
    M(i).cdata = flipud(M(i).cdata);
    clearvars l
   
end


movie2avi(M,'AVITest','fps',15,'Compression', 'none');
clearvars p
clearvars A_video_EXTEM A_Werte i k l n time_EXTEM time_INTEM time_FIBTEM x x_cell y y_cell i 