%% Open data file
dataf2 = importdata('Fig2.csv');
diam_smps = dataf2.data(1,:);
timef3 = dataf2.data(2,:);
%% Calculate the regression
linfit_GR = fitlm(timef3(diam_smps<=25), diam_smps(diam_smps<=25));% Perform linear regression
hours_linfit = 14:21;
[line_GR,ci2] = predict(linfit_GR, hours_linfit','Simultaneous',true,'Alpha',0.05);
%% Call new figure
figure('Position',[1063,340,473,347])
%% Plot the figure
plt1 = plot(hours_linfit', line_GR, '-k','LineWidth',2);
hold on 
scatter(timef3(diam_smps<=25),diam_smps(diam_smps<=25),'filled','o','MarkerFaceColor',[0.85,0.33,0.1])
fill([hours_linfit, fliplr(hours_linfit)], [ci2(:,1)', fliplr(ci2(:,2)')],[0.2 0.2 0.2],'FaceAlpha', 0.2, 'LineStyle','none','FaceColor',[0.5,0.5,0.5]);
GRfit = linfit_GR.Coefficients.Estimate(2);
R2_GRfit = linfit_GR.Rsquared.Ordinary;
text(14.3, 23, sprintf('GR = %.2f \x00B1 %.2f nm h^-^1\nR^2 = %.2f', GRfit, linfit_GR.Coefficients.SE(2), R2_GRfit), 'FontSize', 12,'Color','k','FontWeight','bold');
xlabel('Local Time (h)'),ylabel('Diameter (nm)')
xlim([14 21])
set(gca,'XTick',14:2:21)
ylim([8 26])
xticklabels({'14','16','18','20'})
ylim([9 26])
grid on