data=xlsread('data.xlsx',1,'A:B');
frame=data(:,1);
time=data(:,1)./25;
avgI=data(:,2);
B=transpose(avgI);
[TF,S1,S2]=ischange(B,'linear','Threshold',200);
segline = S1.*(1:3012) + S2;
plot(time,B,time,segline)
legend('Data','Linear Regime')
xlabel('Time / s')
ylabel('Mean gray value')
x = time;
y = B;
index1 = find(x > 54, 1, 'first');
index2 = find(x > 63, 1, 'first');
coefficients = polyfit(x(index1:index2), y(index1:index2), 1)
yFit = polyval(coefficients, x(index1:index2));
hold on;
plot(x(index1:index2), yFit, 'r-', 'LineWidth', 2);
caption = sprintf('Slope from time = %f to time = %f is %f', x(index1), x(index2), slope)
title(caption, 'FontSize', 20)
slope = coefficients(1)
Best Answer