% 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]

% Fit the data to an exponetial 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)*exp(-p(2)*z);
startingValues = [50,1];
coeffs = nlinfit(z,np,fun,startingValues)
n0 = coeffs(1)
mu = coeffs(2)
fittedfun = @(z)n0*exp(-mu*z)

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

legend('data','tilpasset kurve')

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