% Enter the data (these are dummy results)
% Make sure you have the same number of points in the x and y vectors
% t is the time you measured, most conveniently in seconds.
% U is the voltage you measured, most conveniently in volts.
t = [0,   30,   60,  90, 120, 150, 180, 210, 240, 300, 330, 360, 420]
U = [8.4, 7.0, 5.8, 4.9, 4.1, 3.4, 2.8, 2.4, 2.0, 1.7, 1.4, 1.2, 0.99]

% 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,t)p(1)*exp(-t/p(2));
startingValues = [10,100];
coeffs = nlinfit(t,U,fun,startingValues)
U0 = coeffs(1)
tau = coeffs(2)

% Plot the data as o's and the fitted function as a curve
plot(t,U,'o')
hold on
fittedfun = @(t)U0*exp(-t/tau)
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')