figure;
hold all;
x = [-.001, -.0005, 0., .0005, .001];
K = [3.483696, 3.485056, 3.486374, 3.487674, 3.489009];
plot(x, K, '*');
title('K vs x, 20.5 C, Meas 2');
xlabel('x (m)');
ylabel('K');
grid on;
zoom on;
hold off;

p = polyfit(x, K, 1);
slope = p(1);
intercept = p(2);
x_line = [min(x), max(x)];
y_line(1) = slope * x_line(1) + intercept;
y_line(2) = slope * x_line(2) + intercept;
line(x_line, y_line, 'color', 'r', 'linewidth', 1);
text(mean(x_line), mean(y_line) - 0.1 * (y_line(2) - y_line(1)), ['Slope dK/dx = ', num2str(slope), ' 1/m'], 'color', 'r');
text(mean(x_line), mean(y_line) - 0.2 * (y_line(2) - y_line(1)), ['Slope dK/K/dx = ', num2str(slope / K(4)), ' 1/m'], 'color', 'r');  %i=4 is closest to nominal K
