% Enter the data (these are dummy results)
% Make sure you have the same number of points in the x and y vectors
% z is the thickness of the lead plates, most conveniently in mm.
% np is the counting rate, most conveniently in Bq (counts per second).
z = [0,   5,   10,  15, 20, 25]
np = [50, 30,   20,  12,  7,  4]
lnnp = log(np)

% Fit ln of the data to a liner function.
% The resulting coefficients are stored in coefs.
% The starting values are just a very rough guess to help
% speed up the fitting procedure.
fun = @(p,z)p(1) + p(2)*z;
startingValues = [5,0.2];
coeffs = nlinfit(z,lnnp,fun,startingValues)
lnn0 = coeffs(1)
mu = -coeffs(2)
fittedfun = @(z)lnn0 - mu*z

% Plot the data (ln(np(z))) as o's and the fitted function as a curve
plot(z,lnnp,'o')
hold on
xlim
fplot(fittedfun,xlim)

legend('data','tilpasset linje')

% Choose your own histogram axis labels and title
xlabel('x-akse (enhet)')
ylabel('y-akse (enhet)')
title('Figur N: Min tittel')