%Find the fits y = ax + b
P = zeros(50,2);

%Calculate the slope and y-intercepts
for ii = 1:50
    
    P(ii,:) = polyfit(Xs(:,:,ii)*w(:,ii),q(:,ii),1);

end
% P(1,1) = 0;
% P(1,2) = 1000;
clear ii

%Plot Results
fig = figure;
plot(time,P(:,1),'ko','MarkerSize',10,'LineWidth',2)
title('Slope of Linear Fit vs Time','Interpreter','latex','Fontsize',16,'FontWeight','bold','Position',[12.5 1.05 0])
xlabel('Time (Days)','Interpreter','latex','Fontsize',14,'FontWeight','bold')
ylabel('Slope (T-cells/Day)','Interpreter','latex','Fontsize',14,'FontWeight','bold')
set(get(gca,'Title'),'Units','Normalized','Position',[.45,1.04])
set(fig,'PaperUnits','inches','PaperSize',[10 8])
hgexport(fig,'SlopePhase2_1.pdf', hgexport('factorystyle'), 'Format', 'pdf');

fig = figure;
plot(time,P(:,2),'ko','MarkerSize',10,'Linewidth',2)
title('Y-intercept of Linear Fit vs Time','Interpreter','latex','Fontsize',16,'FontWeight','bold','Position',[12.5 1.05 0])
xlabel('Time (Days)','Interpreter','latex','Fontsize',14,'Fontweight','bold')
ylabel('Y-intercept (T-cells)','Interpreter','latex','Fontsize',14,'Fontweight','bold')
set(get(gca,'Title'),'Units','Normalized','Position',[.45,1.04])
set(fig,'PaperUnits','inches','PaperSize',[10 8])
hgexport(fig,'YintPhase2_1.pdf', hgexport('factorystyle'), 'Format', 'pdf');